const util = require('../../../../../../utils/util.js');
const api = require('../../../../../../config/api.js');
const app = getApp();
const recorderManager = wx.getRecorderManager();
var recordInterval = null;
var getOrderByOrderNumInterval = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    photoDialogShow: false,
    maxCommission: 0,
    announcementShow: false,
    distributionOpenid: "",// 分销人的openid
    invitationOpenid: "",//分享人openid
    shareAmountDetailsId: 0,//分享出来团购票种id
    shareAmountDetailsGroupbuyId: 0,//分享出来团购组团id
    userNotJoinOngoingAmount: {},// 用户当前正在分享中的团购信息
    ongoingAmountDetailsGroupbuy: [],//获取正在进行中的团购信息
    userCapital: {},// 用户资金信息
    ticket: { "selectTicketShow": false, "userInfoShow": false, "orangeShellPayShow": false, "groupbuyShow": false, "orangeShellPayProgress": 1, "selectTicketIndex": 0, "selectNumber": 0, "orangeShell": 0, "totalMoney": 0, "next1_submit": false, "groupbuyDialogShow": false, "userInfo": [], "amountDetailsGroupbuyId": "", "groupbuyShowType": 0 },// 关于票种的信息
    amount: {},// 票种信息
    amountDetails: [],//票种详情
    platform: "",//客户端平台
    ordReviewId: '',//点评id
    reviewBottomDeleteShow: false,// 删除点评的确定弹窗
    otherPageIndex: '',// 去其他页面的日记下标
    groupList: [],// 分组的数据
    deleteDiaryDialogShow: false,//删除日记的弹窗
    groupingEmptyDialogShow: false, // 无分组的弹窗
    updateGroupid: '',// 需要修改的分组id
    groupingDialogShow: false,// 有分组的弹窗
    seedDialog: { "show": false, "index": "", "seedRulesDialogShow": false, "diaryInfo": {} },
    poTopHeightInfo: { "height": -84, "scroll": false, "thirdHeight": 0, "pageTopHeight": 0, "pageAllCenterPositionFixedHeight": 0, "poTopHeight": 0, "poTopViewIndex": 0, "pageDiaryHeight": 0, "scrollTop": 0, "scrollViewShow": 2},
    logininfo: {},// 当前用户的登录信息
    circleid: '',//圈子id
    albumInfo: [],// 圈子【图片、文字、音频】详情信息
    mainUser: {},// 圈主信息
    ordContractList: [],//契约信息
    ordInterest: {},// 圈子详情
    energySize: '',// 能量的数量
    ordInterestJoinCount: 0,// 参与数量
    collectionUserCount: 0,// 自己对此圈子收藏数量
    collectionTotalCount: 0,// 圈子总收藏数量
    diaryCount: 0,// 日记数量
    thisInterestJoinUser: {},// 当前用户在圈子中的角色信息
    mainUserSetup: {},// 圈主的基本设置信息
    thisUserFocusCount: 0,// 当前用户对圈主的关注数量
    optimalMoneyResult: {},//最优票种
    mainBasHomeinfo: {},//圈主的主页信息
    circleRecommendPageNum: 1,// 推荐信息的页数
    circleRecommendPageSize: 10,// 推荐信息的页大小
    circleRecommendList: [],//推荐信息
    isCircleRecommendQuery: true,// 是否可以请求推荐信息：用于下拉获取更多
    cancelCollectionShow: false, // 取消收藏时的弹窗
    moreShow: false, //底部更多弹框
    interestJoinList: [],// 组员数据
    reviewBottomEditorAndDeleteIsShow: false, // 点评底部弹出时是否显示编辑和删除
    reviewBottomIndex: '',// 点评底部弹出时的日记的index
    reviewBottomYIndex: '',// 点评底部弹出时的点评的index
    review_diary: {},// 正在点评的日记信息
    reviewDialogShow: false,// 控制点评的弹窗显示
    reviewBottomShow: false,// 点评底部的的弹出显示
    reviewImageList: { "imageList": [{ "clickNumber": 0 }, { "clickNumber": 0 }, { "clickNumber": 0 }, { "clickNumber": 0 }, { "clickNumber": 0 }], "totalScore": 0 },// 点评的分数
    reviewTextareaShow: false,// 控制点评的textarea是否显示
    reviewTextarea: "",//点评的textarea的值
    reviewAudio: {},// 点评的音频
    reviewImage: {},// 点评的图片
    audioOauhRefusedDialogShow: false,// 语音拒绝授权的弹窗
    isSubmitAll: false,// 是否正在发布点评
    diary_commones_dialog: false,// 评论回复成功之后的弹窗
    ordReviewQuickTextLength: 0,// 快捷语的texteare的长度
    ordReviewQuickText: '',// 快捷语的texteare
    quickLanguageShow: false, // 添加快捷语的弹窗显示
    ordReviewQuickId: '',// 快捷语的id
    selectReviewQuickIndex: "", //快捷评语选中的下标
    quickLanguageBottomShow: false, // 快捷语底部的的弹出显示
    ordAppreciate: {},// 鼓励赞赏
    diaryCommentsid: '', // 评论的id
    isCommonsDelete: false, // 是否显示评论的删除
    replyCommentNickname: '', // 被评论回复的昵称
    mainReplyCommentsid: 0, // 评论回复的主id
    replyCommentsid: 0, // 评论回复的id
    commentsAudio: {}, // 评论的语音
    commentsTextarea: '', // 评论的texteare
    commonsBottomShow: false, // 评论的底部是否显示
    saveCommentsIndex: '', //提交评论的日记下标
    commentsDialogShow: false, //评论的弹窗
    diaryOperationShow: false, // 日记操作的底部显示
    diaryOperationShowInfo: {}, // 日记操作的主要数据信息
    diaryInfoList: [], // 日记信息
    diaryInfoPageNum: 1, // 日记详情的页数
    diaryInfoPageSize: 10, // 日记详情的每页大小数
    diaryInfoTotalPages: 0, // 日记详情的总页数
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    var platform = wx.getSystemInfoSync().platform;
    var circleid = options.circleid;
    var shareAmountDetailsGroupbuyId = options.shareAmountDetailsGroupbuyId;
    var shareAmountDetailsId = options.shareAmountDetailsId;
    var invitationOpenid = options.invitationOpenid;
    var distributionOpenid = options.distributionOpenid;
    var backgroundAudioManager = wx.getBackgroundAudioManager();
    wx.pauseBackgroundAudio();//暂停播放音乐
    backgroundAudioManager.pause();//暂停播放音乐
    _this.setData({
      platform: platform,
      circleid: circleid,
      logininfo: app.globalData.logininfo,
    })
    if (shareAmountDetailsGroupbuyId != null && shareAmountDetailsGroupbuyId > 0) {
      _this.setData({
        shareAmountDetailsGroupbuyId: shareAmountDetailsGroupbuyId
      })
    }
    if (shareAmountDetailsId != null && shareAmountDetailsId > 0) {
      _this.setData({
        shareAmountDetailsId: shareAmountDetailsId
      })
    }
    if (invitationOpenid != null && invitationOpenid.length > 0) {
      _this.setData({
        invitationOpenid: invitationOpenid
      })
    }
    if (distributionOpenid != null && distributionOpenid.length > 0) {
      _this.setData({
        distributionOpenid: distributionOpenid
      })
    }
    // 计算scrollview的高度
    _this.pageAllCenterPositionFixedHeight();
    // 获取圈子信息
    _this.getCircleDetails();
    // 获取日记信息
    _this.getDiaryInfo();
    // 修改圈子的预览次数
    _this.addIspreview();
    //获取圈子票种信息
    _this.getOrdAmounts();
    // 获取用户资金信息
    _this.getUserCapital();
    // 获取正在进行中的团购信息
    _this.getOngoingAmountDetailsGroupbuy();

    var poTopViewIndex = options.poTopViewIndex;
    if (poTopViewIndex == 1){
      // 需要固定到目录
      wx.showLoading({
        title: '加载中',
      })
      setTimeout(function () {
        wx.pageScrollTo({
          scrollTop: 200,
          duration: 10
        })
        _this.setData({
          ["poTopHeightInfo.scroll"]: false
        })
      }, 1500);
      setTimeout(function () {
        var dataset = { "index": 1 };
        var currentTarget = { "dataset": dataset };
        var e = { "currentTarget": currentTarget };
        _this.poTopViewTap(e);
        _this.setData({
          ["poTopHeightInfo.scroll"]: false
        })
      }, 2000);
      setTimeout(function () {
        _this.setData({
          ["poTopHeightInfo.scroll"]: true,
          ["poTopHeightInfo.poTopViewIndex"]: 1,
          ["poTopHeightInfo.scrollViewShow"]: 1,
          ["poTopHeightInfo.scrollTop"]: 0
        })
        wx.hideLoading();
      }, 2500);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this;
    // 获取分组信息
    _this.getGroup();
    // 获取用户快捷评语
    _this.getOrdReviewQuick();
    //获取圈子票种信息
    _this.getOrdAmounts();
    // 获取用户资金信息
    _this.getUserCapital();
    // 获取正在进行中的团购信息
    _this.getOngoingAmountDetailsGroupbuy();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var _this = this;
    _this.getCircleDetails();
    //获取圈子票种信息
    _this.getOrdAmounts();
    // 获取用户资金信息
    _this.getUserCapital();
    // 获取正在进行中的团购信息
    _this.getOngoingAmountDetailsGroupbuy();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    var _this = this;
    var id = _this.data.circleid;
    var ischeckshare = "";
    var type = "";
    var index = "";
    if (e.target != null && e.target.dataset != null) {
      type = e.target.dataset.type;
      index = e.target.dataset.index;
      ischeckshare = e.target.dataset.ischeckshare;
    }
    if (type == "2") {
      // 分享的是日记
      var diaryInfo = _this.data.diaryInfoList[index];
      var nickname = diaryInfo.diaryUserInfo.nickname;
      var imageVideoList = diaryInfo.imageVideoList;
      var imageUrl = _this.data.ordInterest.postersIp + _this.data.ordInterest.posterImageUrl;
      for (var i = 0; i < imageVideoList.length; i++) {
        if (imageVideoList[i].imageVideoType == "1") {
          imageUrl = imageVideoList[i].ip + imageVideoList[i].url;
          break;
        }
      }
      return {
        title: nickname + "的日记",
        path: 'pages/home/shareJump/shareJump?id=' + id + "&type=" + util.getShareType("diary") + "&isCheckLogin=1&circleid=" + _this.data.circleid,
        imageUrl: imageUrl
      }
    } else if(type == 3){
      // 邀请好友拼团
      var openid = app.globalData.logininfo.openid;
      var nickName = app.globalData.logininfo.userInfo.nickName;
      var amountdetailsgroupbuyid = e.target.dataset.amountdetailsgroupbuyid;
      var amountdetailsid = e.target.dataset.amountdetailsid;
      var amountImage = _this.data.ordInterest.postersIp + _this.data.ordInterest.posterImageUrl;
      var data = { "amountdetailsid": amountdetailsid};
      console.log(e);
      console.log('pages/home/shareJump/shareJump?id=' + amountdetailsgroupbuyid + "&type=" + util.getShareType("groupbuyTicket") + "&isCheckLogin=1&circleid=" + _this.data.circleid + "&shareOpenid=" + openid + "&data=" + JSON.stringify(data));
      return {
        title: nickName + "邀请您参与拼团",
        path: 'pages/home/shareJump/shareJump?id=' + amountdetailsgroupbuyid + "&type=" + util.getShareType("groupbuyTicket") + "&isCheckLogin=1&circleid=" + _this.data.circleid + "&shareOpenid=" + openid + "&data=" + JSON.stringify(data),
        imageUrl: amountImage
      }
    } else {
      var nickName = app.globalData.logininfo.userInfo.nickName;
      return {
        title: nickName + "邀请您加入圈子",
        path: 'pages/home/shareJump/shareJump?id=' + id + "&type=" + util.getShareType("circle") + "&shareOpenid=" + openid + "&isCheckLogin=1"
      }
    }
  },

  /**
  * 监听屏幕滚动 判断上下滚动
  */
  onPageScroll: function (e) {
    var _this = this;
    var poTopViewIndex = _this.data.poTopHeightInfo.poTopViewIndex;
      var scrollTop = parseInt(e.scrollTop);
      var poTopHeightInfo = _this.data.poTopHeightInfo;
      var pageTopHeight = poTopHeightInfo.pageTopHeight;
      var poTopHeight = poTopHeightInfo.poTopHeight;
      var pageDiaryHeight = poTopHeightInfo.pageDiaryHeight;
      var scroll = poTopHeightInfo.scroll;
      if (pageDiaryHeight == null || pageDiaryHeight <= 0) {
        var query = wx.createSelectorQuery();
        query.select('.page_diary').boundingClientRect(function (rect) {
          var height = rect.height + 14;
          _this.setData({
            ["poTopHeightInfo.pageDiaryHeight"]: height
          })
        }).exec();
      }
      if (poTopHeight == null || poTopHeight <= 0) {
        var query = wx.createSelectorQuery();
        query.select('.po_top').boundingClientRect(function (rect) {
          var height = rect.height;
          _this.setData({
            ["poTopHeightInfo.poTopHeight"]: height
          })
        }).exec();
      }
      if (pageTopHeight == null || pageTopHeight <= 0) {
        var query = wx.createSelectorQuery();
        query.select('.page_top').boundingClientRect(function (rect) {
          var height = rect.height;
          _this.setData({
            ["poTopHeightInfo.pageTopHeight"]: height
          })
        }).exec();
      } else if (!scroll) {
        var bl = -84 + (scrollTop / parseInt(pageTopHeight - poTopHeight) * 84);
        if (bl <= 0) {
          _this.setData({
            ["poTopHeightInfo.height"]: bl
          })
        } else {
          _this.setData({
            ["poTopHeightInfo.height"]: 0
          })
        }
        if (bl >= 0) {
          //  设置标题
          wx.setNavigationBarTitle({
            title: _this.data.ordInterest.title
          })
          if (poTopViewIndex != 1) {
            _this.setData({
              ["poTopHeightInfo.poTopViewIndex"]: 2
            })
          }
        } else {
          wx.setNavigationBarTitle({
            title: ""
          })
          if (poTopViewIndex != 1) {
            _this.setData({
              ["poTopHeightInfo.poTopViewIndex"]: 0
            })
          }
        }
      }

      var thirdHeight = poTopHeightInfo.thirdHeight;
      if (thirdHeight == null || thirdHeight <= 0) {
        var query = wx.createSelectorQuery();
        query.select('.thirdHeight').boundingClientRect(function (rect) {
          var height = rect.height;
          _this.setData({
            ["poTopHeightInfo.thirdHeight"]: height
          })
        }).exec();
      } else {
        var scrollViewShow = _this.data.poTopHeightInfo.scrollViewShow;
        if (scrollTop >= thirdHeight - poTopHeight) {
          _this.setData({
            ["poTopHeightInfo.scroll"]: true
          })
          if (scrollViewShow == 1) {
            _this.setData({
              ["poTopHeightInfo.poTopViewIndex"]: 1
            })
          }
        } else {
          _this.setData({
            ["poTopHeightInfo.scroll"]: false
          })
        }
      }
  },

  /**
   * 获取圈子信息
   */
  getCircleDetails: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var data = {};
    data.circleid = circleid;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getCircleDetailsQuery(api.Home_GetCircleDetailsApiUrl, data);
      })
    } else {
      _this.getCircleDetailsQuery(api.Home_GetCircleDetailsUrl, data);
    }
  },

  /**
   * 获取圈子信息：请求
   */
  getCircleDetailsQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var json = res.result.json;
        if (json != null) {
          var optimalMoneyResult = json.optimalMoneyResult;
          if (optimalMoneyResult != null && optimalMoneyResult.preferentialAmountDetails != null) {
            var preferentialAmountDetails = JSON.parse(JSON.stringify(optimalMoneyResult.preferentialAmountDetails));
            optimalMoneyResult.preferentialAmountDetails = JSON.parse(preferentialAmountDetails);
          }
          var join_text = "";
          if (optimalMoneyResult.isExperienceSwitch == 1){
            join_text = "免费体验";
          } else if (optimalMoneyResult.isExperienceSwitch == 0){
            if (optimalMoneyResult.ticketType == 0){
              join_text = "免费";
            } else if (optimalMoneyResult.ticketType == 1) {
              join_text = "限时优惠";
            } else if (optimalMoneyResult.ticketType == 2) {
              join_text = "限时团购";
            } else if (optimalMoneyResult.ticketType == 3) {
              join_text = "橙贝兑换";
            } else if (optimalMoneyResult.ticketType == 4) {
              join_text = "抢位报名";
            } else if (optimalMoneyResult.ticketType == 5) {
              join_text = "立即加入";
            }
          }
          _this.setData({
            albumInfo: json.albumInfo,
            mainUser: json.mainUser,
            ordContractList: json.ordContractList,
            ordInterest: json.ordInterest,
            energySize: json.energySize,
            ordInterestJoinCount: json.ordInterestJoinCount,
            collectionUserCount: json.collectionUserCount,
            collectionTotalCount: json.collectionTotalCount,
            diaryCount: json.diaryCount,
            thisInterestJoinUser: json.thisInterestJoinUser,
            mainUserSetup: json.mainUserSetup,
            optimalMoneyResult: optimalMoneyResult,
            mainBasHomeinfo: json.mainBasHomeinfo,
            ordAppreciate: json.ordAppreciate,
            thisUserFocusCount: json.thisUserFocusCount,
            join_text: join_text,
            maxCommission: json.maxCommission
          })

          // 获取圈子推荐数据
          _this.getCircleRecommendInfo();

          var ordInterest_circleNotice = json.ordInterest.circleNotice;
          if (null != json.thisInterestJoinUser){
            var thisInterestJoinUser_circleNotice = json.thisInterestJoinUser.circleNotice;
            if (ordInterest_circleNotice != thisInterestJoinUser_circleNotice && ordInterest_circleNotice != null && ordInterest_circleNotice.length > 0 && json.thisInterestJoinUser.identitytype == 0) {
              _this.announcementTap();
            }
          }
        }
      }
    });
  },

  /**
   * 公告栏的弹出
   */
  announcementTap: function () {
    var _this = this;
    var announcementShow = _this.data.announcementShow;
    _this.setData({
      announcementShow: !announcementShow
    })
    if (announcementShow) {
      var ordInterest_circleNotice = _this.data.ordInterest.circleNotice;
      var thisInterestJoinUser_circleNotice = _this.data.thisInterestJoinUser.circleNotice;
      if (ordInterest_circleNotice != thisInterestJoinUser_circleNotice) {
        _this.updateCircleNoticeByJoin();
      }
    }
  },

  /**
   * 修改圈子参与用户的公告
   */
  updateCircleNoticeByJoin: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = _this.data.circleid;
        data.circleNotice = _this.data.ordInterest.circleNotice;
        util.post(api.Home_UpdateCircleNoticeByJoinApiUrl, data).then(function (res) { });
      })
    }
  },
  
  /**
   * 获取圈子的推荐信息
   */
  getCircleRecommendInfo: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var openid = _this.data.logininfo.openid;
    var circleRecommendPageNum = _this.data.circleRecommendPageNum;
    var circleRecommendPageSize = _this.data.circleRecommendPageSize;
    var thisInterestJoinUser = _this.data.thisInterestJoinUser;
    var identitytype = thisInterestJoinUser == null ? 0 : thisInterestJoinUser.identitytype;
    var data = {};
    data.circleid = circleid;
    data.pageNum = circleRecommendPageNum;
    data.pageSize = circleRecommendPageSize;
    data.isObtainSystemRecommend = identitytype != 1 ? "1" : "0";
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getCircleRecommendInfoQuery(api.Home_GetCircleRecommendInfoApiUrl, data);
      })
    } else {
      _this.getCircleRecommendInfoQuery(api.Home_GetCircleRecommendInfoUrl, data);
    }
  },

  /**
   * 获取圈子的推荐信息：请求
   */
  getCircleRecommendInfoQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var resultList = res.result.list;
        var list = _this.data.circleRecommendList;
        for (var i = 0; i < resultList.length; i++) {
          var optimalMoneyResult = resultList[i].optimalMoneyResult;
          if (optimalMoneyResult != null){
            var preferentialAmountDetails = optimalMoneyResult.preferentialAmountDetails;
            if (preferentialAmountDetails != null && preferentialAmountDetails.length > 0){
              resultList[i].optimalMoneyResult.preferentialAmountDetails = JSON.parse(preferentialAmountDetails);
            }
          }
          list.push(resultList[i]);
        }
        _this.setData({
          circleRecommendList: list,
          isCircleRecommendQuery: resultList.length > 0 ? true : false
        })
      }
    });
  },

  /**
   * 获取更多圈子的推荐信息
   */
  gettCircleRecommendInfoMore: function(){
    var _this = this;
    var isCircleRecommendQuery = _this.data.isCircleRecommendQuery;
    if (isCircleRecommendQuery) {
      var circleRecommendPageNum = _this.data.circleRecommendPageNum;
      _this.setData({
        circleRecommendPageNum: circleRecommendPageNum + 1
      })
      _this.getCircleRecommendInfo();
    }
  },

  /**
   * 跳转到编辑页面
   */
  navigateToEditdetails: function(){
    var _this = this;
    var circleid = _this.data.circleid;
    wx.navigateTo({
      url: '../../editdetails/editdetails?circleid=' + circleid + "&energyInfoResults=false"
    })
  },

  /**
   * scroll-view滚动事件
   */
  bindScroll: function(e){
    var _this = this;
    var poTopViewIndex = _this.data.poTopHeightInfo.poTopViewIndex;
    var scrollViewShow = _this.data.poTopHeightInfo.scrollViewShow;
    if (scrollViewShow == 2) {
      var pageDiaryHeight = _this.data.poTopHeightInfo.pageDiaryHeight;
      var scrollTop = e.detail.scrollTop;
      if (scrollTop >= pageDiaryHeight) {
        _this.setData({
          ["poTopHeightInfo.poTopViewIndex"]: 3
        })
      } else {
        _this.setData({
          ["poTopHeightInfo.poTopViewIndex"]: 2
        })
      }
    }
  },

  /**
   * 头部的标签点击事件
   */
  poTopViewTap: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var poTopHeightInfo = _this.data.poTopHeightInfo;
    if (index == 1) {
      // 目录
      _this.setData({
        ["poTopHeightInfo.poTopViewIndex"]: 1,
        ["poTopHeightInfo.scrollViewShow"]: 1,
        ["poTopHeightInfo.scroll"]: true,
        ["poTopHeightInfo.scrollTop"]: 0
      })
      var thirdHeight = poTopHeightInfo.thirdHeight;
      wx.pageScrollTo({
        scrollTop: thirdHeight,
        duration: 300
      })
    } else if (index == 2) {
      // 介绍
      _this.setData({
        ["poTopHeightInfo.scrollTop"]: 0,
        ["poTopHeightInfo.scroll"]: false,
        ["poTopHeightInfo.poTopViewIndex"]: 2,
        ["poTopHeightInfo.scrollViewShow"]: 2
      })
      var poTopHeight = poTopHeightInfo.poTopHeight;
      var pageTopHeight = poTopHeightInfo.pageTopHeight;
      wx.pageScrollTo({
        scrollTop: pageTopHeight - poTopHeight + 6,
        duration: 300
      })
    } else if (index == 3) {
      // 猜你喜欢
      var thirdHeight = poTopHeightInfo.thirdHeight;
      var pageDiaryHeight = poTopHeightInfo.pageDiaryHeight;
      wx.pageScrollTo({
        scrollTop: thirdHeight,
        duration: 300
      })
      setTimeout(function () {
        _this.setData({
          ["poTopHeightInfo.scroll"]: true,
          ["poTopHeightInfo.poTopViewIndex"]: 3,
          ["poTopHeightInfo.scrollViewShow"]: 2
        })
        _this.setData({
          ["poTopHeightInfo.scrollTop"]: pageDiaryHeight
        })
      }, 400)
    }
  },

  /**
   * 计算scrollview的高度
   */
  pageAllCenterPositionFixedHeight: function(){
    var _this = this;
    var query = wx.createSelectorQuery();
    query.select('.po_top').boundingClientRect(function (rect) {
      var windowHeight = wx.getSystemInfoSync().windowHeight;
      var height = rect.height;
      _this.setData({
        ["poTopHeightInfo.pageAllCenterPositionFixedHeight"]: "height:" + (parseInt(windowHeight) - parseInt(height)) + "px",
        ["poTopHeightInfo.poTopHeight"]: height
      })
    }).exec();
  },

  /**
   * 获取日记详情
   */
  getDiaryInfo: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var diaryInfoPageNum = _this.data.diaryInfoPageNum;
    var diaryInfoPageSize = _this.data.diaryInfoPageSize;
    var openid = _this.data.logininfo.openid;
    var data = {};
    data.circleid = circleid;
    data.pageNum = diaryInfoPageNum;
    data.pageSize = diaryInfoPageSize;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getDiaryInfoQuery(api.Home_GetDiaryInfoApiUrl, data);
      })
    } else {
      _this.getDiaryInfoQuery(api.Home_GetDiaryInfoUrl, data);
    }
  },

  /**
   * 获取日记详情：请求
   */
  getDiaryInfoQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var diaryInfoTotalPages = res.result.pages;
        var resultList = res.result.list;
        var list = _this.data.diaryInfoList;
        for (var i = 0; i < resultList.length; i++) {
          list.push(resultList[i]);
        }
        _this.setData({
          diaryInfoList: list,
          diaryInfoTotalPages: diaryInfoTotalPages
        })
        _this.calculateHeight();
      }
    });
  },

  /**
   * 计算高度
   */
  calculateHeight: function () {
    var _this = this;
    var diaryInfoList = _this.data.diaryInfoList;
    for (var i = 0; i < diaryInfoList.length; i++) {
      var diaryTextList = diaryInfoList[i].diaryTextList;
      for (var y = 0; y < diaryTextList.length; y++) {
        var id = "#diaryText_" + i + "_" + y;
        var query = wx.createSelectorQuery();
        query.select(id).boundingClientRect(function (rect) {
          var id = rect.id;
          var diaryInfoIndex = id.split("_")[1];
          var diaryTextIndex = id.split("_")[2];
          var height = rect.height;
          if (height > 72) {
            _this.setData({
              ["diaryInfoList[" + diaryInfoIndex + "].diaryTextList[" + diaryTextIndex + "].isOverflow"]: true
            })
          }
        }).exec();
      }
    }
  },

  /**
   * 日记详情
   */
  toDiaryDetails: function (e) {
    var _this = this;
    _this.diaryOperationClose();
    var circleid = _this.data.circleid;
    var index = e.currentTarget.dataset.index;
    var diaryid = _this.data.diaryInfoList[index].ordDiary.id;
    _this.setData({
      otherPageIndex: index
    })
    wx.navigateTo({
      url: '../circleinteraction/diaryDetails/diaryDetails?circleid=' + circleid + '&diaryid=' + diaryid
    })
  },

  /**
   * 进入用户主页
   */
  navigateToPersonhome: function (e) {
    var openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: '../../../personhome/personhome?openid=' + openid
    })
  },

  /**
   * 日记操作的底部展示弹窗
   */
  diaryOperationShow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var diaryInfo = _this.data.diaryInfoList[index];
    var isPlacedtop = diaryInfo.ordDiary.isPlacedtop; // 是否加精
    var id = diaryInfo.ordDiary.id;
    var diaryOperationShowInfo = {
      "index": index,
      "isPlacedtop": isPlacedtop,
      "ordDiaryid": id,
      "diaryInfo": diaryInfo
    };
    _this.setData({
      diaryOperationShow: true,
      diaryOperationShowInfo: diaryOperationShowInfo
    })
  },

  /**
   * 日记操作的底部关闭弹窗
   */
  diaryOperationClose: function () {
    var _this = this;
    _this.setData({
      updateGroupid: "",
      groupingDialogShow: false,
      diaryOperationShow: false,
      diaryOperationShowInfo: {}
    })
  },

  /**
   * 预览图片：日记
   */
  previewImage: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var diaryInfo = _this.data.diaryInfoList[index];
    var imageList = diaryInfo.imageVideoList;
    var urls = [];
    var current = diaryInfo.imageVideoList[yindex].ip + diaryInfo.imageVideoList[yindex].url;
    for (var i = 0; i < imageList.length; i++) {
      if (imageList[i].imageVideoType == "1") {
        urls.push(imageList[i].ip + imageList[i].url);
      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
   * 预览图片：正在编辑的点评图片
   */
  previewSaveReviewImage: function (e) {
    var _this = this;
    var reviewImage = _this.data.reviewImage;
    wx.previewImage({
      current: reviewImage.path, // 当前显示图片的http链接
      urls: [reviewImage.path] // 需要预览的图片http链接列表
    })
  },

  /**
   * 跳转到视频播放页面：日记
   */
  navigateToVideo: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var diaryInfo = _this.data.diaryInfoList[index];
    var video = diaryInfo.imageVideoList[yindex];
    var diaryid = diaryInfo.ordDiary.id;
    var src = video.ip + video.url;
    wx.navigateTo({
      url: "../../../../../../pages/home/video/video?state=1&type=2&id=" + diaryid + "&src=" + src
    })
  },

  /**
   * 播放或暂停动作：日记
   */
  voiceBoFang_diary: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var diaryAudioList = _this.data.diaryInfoList[index].diaryAudioList[yindex];
    var boFangImage = diaryAudioList.boFangImage;
    var ip = diaryAudioList.ip;
    var name = diaryAudioList.name;
    var currentTime = diaryAudioList.currentTime;
    var audiourl = diaryAudioList.url;
    var backgroundAudioManager = wx.getBackgroundAudioManager(); //获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      // 切换至暂停状态
      wx.pauseBackgroundAudio(); //暂停播放音乐
      backgroundAudioManager.pause(); //暂停播放音乐
      _this.setData({
        ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio(); ////暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime; //设置音乐开始时间
      backgroundAudioManager.title = name;
      backgroundAudioManager.src = ip + audiourl;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: "00:00",
          ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: 0,
          ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = parseInt(backgroundAudioManager.currentTime);
        var startDate = util.digitalFormatTime(position);
        _this.setData({
          ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: backgroundAudioManager.currentTime,
          ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
        });
      })
      _this.setData({
        ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioBoFangImage_Name
      });
    }
  },

  /**
   * 播放音乐（滚动条事件）：日记
   */
  voiceSlider_diary: function (e) {
    var _this = this;
    var position = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var diaryAudioList = _this.data.diaryInfoList[index].diaryAudioList[yindex];
    var boFangImage = diaryAudioList.boFangImage;
    var startDate = util.digitalFormatTime(position);
    var backgroundAudioManager = wx.getBackgroundAudioManager(); //获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
      _this.setData({
        ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
        ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
      });
      _this.voiceBoFang_diary(e);
    } else {
      // 未播放状态
      _this.setData({
        ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
        ["diaryInfoList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
      });
    }
  },

  /**
   * 文字的全文展开
   */
  diaryTextOverflow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    _this.setData({
      ["diaryInfoList[" + index + "].diaryTextList[" + yindex + "].isOverflow"]: false
    })
  },

  /**
   * 跳转到公众号展示页面：日记
   */
  navigateToWebView: function (e) {
    var ip = e.currentTarget.dataset.ip;
    var text = e.currentTarget.dataset.text;
    var type = e.currentTarget.dataset.type;
    if (type == 1) {
      wx.navigateTo({
        url: '../../../../../../pages/home/webView/webView?src=' + text,
      })
    } else {
      wx.downloadFile({
        url: ip + text,
        success: function (res) {
          var filePath = res.tempFilePath;
          wx.openDocument({
            filePath: filePath,
            success: function (res) { }
          })
        }
      })
    }
  },

  /**
   * 添加或删除日记能量点赞
   */
  saveOrDeleteOrdDiaryGivelike: function (e) {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var index = e.currentTarget.dataset.index;
    var diaryGivelikeid = e.currentTarget.dataset.givelikeid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = _this.data.circleid;
        data.diaryid = _this.data.diaryInfoList[index].ordDiary.id;
        data.diaryGivelikeid = diaryGivelikeid;
        util.post(api.Home_SaveOrDeleteOrdDiaryGivelikeApiUrl, data).then(function (res) {
          if (res.code == 200) {
            _this.getDiaryInfoByDiaryId(index);
            var energyInfoResults = res.result.energyInfoResults;
            if (energyInfoResults == true) {
              _this.setData({
                diary_givelike_dialog: true
              })
              setTimeout(() => {
                _this.setData({
                  diary_givelike_dialog: false
                })
              }, 2000);
            }
          }
        })
      })
    }
  },

  /**
   * 获取单个单个日记详情
   */
  getDiaryInfoByDiaryId: function (index) {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var data = {};
    data.circleid = _this.data.circleid;
    data.ordDiaryid = _this.data.diaryInfoList[index].ordDiary.id;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getDiaryInfoByDiaryIdQuery(index, api.Home_GetDiaryInfoByDiaryIdApiUrl, data);
      })
    } else {
      _this.getDiaryInfoByDiaryIdQuery(index, api.Home_GetDiaryInfoByDiaryIdUrl, data);
    }
  },

  /**
   * 获取单个日记详情：请求
   */
  getDiaryInfoByDiaryIdQuery: function (index, url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var json = res.result.json;
        var diaryTextList = _this.data.diaryInfoList[index].diaryTextList;
        json.diaryTextList = diaryTextList;
        _this.setData({
          ["diaryInfoList[" + index + "]"]: json
        });
      }
    });
  },

  /**
   * 评论的弹窗打开
   */
  commentsDialogShow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      commentsDialogShow: true,
      saveCommentsIndex: index,
      commonsBottomShow: false
    })
  },

  /**
   * 评论的弹窗关闭
   */
  commentsDialogClose: function () {
    var _this = this;
    _this.deleteCommentsRecorder();
    _this.setData({
      commentsTextarea: '',
      commentsAudio: {},
      commentsDialogShow: false,
      saveCommentsIndex: '',
      replyCommentsid: 0,
      mainReplyCommentsid: 0,
      replyCommentNickname: ''
    })
  },

  /**
   * 评论的texteare的输入事件
   */
  commentsTextareaInput: function (e) {
    var _this = this;
    var commentsTextarea = e.detail.value;
    _this.setData({
      commentsTextarea: commentsTextarea
    })
  },

  /**
   * 评论录音
   */
  commentsAudioTap: function () {
    var _this = this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.record']) {
          // 未授权
          wx.authorize({
            scope: 'scope.record',
            success() {
              _this.commentsAudioStart();
            },
            fail: function () {
              // 拒绝授权
              _this.setData({
                audioOauhRefusedDialogShow: true
              })
            }
          })
        } else {
          // 已授权
          _this.commentsAudioStart();
        }
      }
    })
  },

  /**
   * 开始录音：评论
   */
  commentsAudioStart: function () {
    var _this = this;
    var commentsAudio = {};
    commentsAudio.isupload = true;
    commentsAudio.state = "1"; // 1正在录音  2录音完毕（state==2的时候，playState无效）
    commentsAudio.playState = "1"; // 1正常录音  2暂停录音
    commentsAudio.isBoFang = "0";
    commentsAudio.totalTime = 0;
    commentsAudio.totalDate = "00:00";
    commentsAudio.isVoiceDialogShow = true;
    _this.setData({
      commentsAudio: commentsAudio
    })

    const recorderOptions = {
      duration: util.getAudioFileMaxTime("diaryComments"), //指定录音的时长，单位 ms，默认十分钟
      format: 'mp3'
    }
    //开始录音
    recorderManager.start(recorderOptions);

    // 定时器计算录音时间
    _this.doCommentsRecordInterval();

    // 录音结束
    recorderManager.onStop((res) => {
      _this.commentsStopRecorderExecute(res);
    });

    // 录音中断
    recorderManager.onInterruptionBegin((res) => {
      recorderManager.stop();
      _this.commentsStopRecorderExecute(res);
    });
  },

  /**
   * 停止录音后的业务代码：评论
   */
  commentsStopRecorderExecute: function (tempFile) {
    var _this = this;
    _this.doClearInterval();
    var isVoiceDialogShow = _this.data.commentsAudio.isVoiceDialogShow;
    if (isVoiceDialogShow) {
      var totalTime = parseInt(tempFile.duration / 1000);
      var commentsAudio = _this.data.commentsAudio;
      commentsAudio.state = "2";
      commentsAudio.src = tempFile.tempFilePath;
      commentsAudio.title = "录音音频";
      commentsAudio.currentTime = 0;
      commentsAudio.totalTime = totalTime;
      commentsAudio.fileSize = tempFile.fileSize;
      commentsAudio.startDate = "00:00";
      commentsAudio.totalDate = util.digitalFormatTime(totalTime);
      commentsAudio.isBoFang = "0";
      _this.setData({
        commentsAudio: commentsAudio
      })
    } else {
      /*_this.setData({
        commentsAudio: {}
      })*/
    }
  },

  /**
   * 删除录音：评论
   */
  deleteCommentsRecorder: function () {
    var _this = this;
    _this.setData({
      ["commentsAudio.isVoiceDialogShow"]: false,
      commentsAudio: {}
    })
    _this.doClearInterval();
    recorderManager.stop();
  },

  /**
   * 清空录音：评论
   */
  clearCommentsRecorder: function () {
    var _this = this;
    _this.setData({
      ["commentsAudio.isVoiceDialogShow"]: false
    })
    _this.doClearInterval();
    recorderManager.stop();

    setTimeout(function () {
      _this.commentsAudioTap();
    }, 100)
  },

  /**
   * 定时器计算录音时间：评论
   */
  doCommentsRecordInterval: function () {
    var _this = this;
    if (recordInterval == null) {
      recordInterval = setInterval(function () {
        var commentsAudio = _this.data.commentsAudio;
        var totalTime = commentsAudio.totalTime + 1;
        var totalDate = util.digitalFormatTime(totalTime);
        _this.setData({
          ["commentsAudio.totalTime"]: totalTime,
          ["commentsAudio.totalDate"]: totalDate
        });
      }, 1000);
    }
  },

  /**
   * 暂停录音：评论
   */
  commentsPauseRecorder: function (e) {
    var _this = this;
    _this.setData({
      ["commentsAudio.playState"]: "2"
    });
    recorderManager.pause();
    _this.doClearInterval();
  },

  /**
   * 继续录音：评论
   */
  commentsResumeRecorder: function (e) {
    var _this = this;
    _this.setData({
      ["commentsAudio.playState"]: "1"
    })
    recorderManager.resume();
    _this.doCommentsRecordInterval();
  },

  /**
   * 停止录音：评论
   */
  commentsStopRecorder: function (e) {
    var _this = this;
    recorderManager.stop();
    recorderManager.onStop((res) => {
      _this.commentsStopRecorderExecute(res);
    });
  },

  /**
   * 播放或暂停动作
   */
  commentsAudioBoFang: function (e) {
    var _this = this;
    var src = _this.data.commentsAudio.src;
    var title = _this.data.commentsAudio.title;
    var currentTime = _this.data.commentsAudio.currenttime;
    var isBoFang = _this.data.commentsAudio.isBoFang;
    var backgroundAudioManager = wx.getBackgroundAudioManager(); //获取全局唯一的背景音频管理器
    if (isBoFang == "1") {
      // 切换至暂停状态
      backgroundAudioManager.pause(); //暂停播放音乐
      _this.setData({
        ["commentsAudio.isBoFang"]: "0"
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio(); //暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime; //设置音乐开始时间
      backgroundAudioManager.title = title;
      backgroundAudioManager.src = src;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["commentsAudio.currentTime"]: 0,
          ["commentsAudio.isBoFang"]: "0",
          ["commentsAudio.startDate"]: "00:00"
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = Math.round(backgroundAudioManager.currentTime);
        var voiceStartDate = util.digitalFormatTime(position);
        _this.setData({
          ["commentsAudio.currentTime"]: backgroundAudioManager.currentTime,
          ["commentsAudio.startDate"]: voiceStartDate
        });
      })

      _this.setData({
        ["commentsAudio.isBoFang"]: "1"
      });
    }
  },

  /**
   * 发表评论
   */
  submitComments: function () {
    var _this = this;
    var commentsTextarea = _this.data.commentsTextarea;
    var commentsAudio = _this.data.commentsAudio;
    if (!(commentsTextarea.length > 0 || (commentsAudio.state != null && commentsAudio.state.length > 0))) {
      util.dialogAlert("评论内容不能为空");
      return false;
    } else if (commentsAudio.state != null && commentsAudio.state == "1") {
      util.dialogAlert("正在录制音频中");
      return false;
    }
    wx.showLoading({
      title: '保存中',
    })
    _this.setData({
      isSubmitAll: false
    })
    var uploadInfoList = [];
    if (commentsAudio.state != null && commentsAudio.state == "2" && commentsAudio.isupload) {
      var uploadInfo = {};
      uploadInfo.type = "2"; // 类型:1图片  2音频  3视频
      uploadInfo.filePath = commentsAudio.src;
      uploadInfoList.push(uploadInfo);
    }
    if (uploadInfoList.length > 0) {
      // 开始请求:要先上传
      _this.uploadCommentsFileQuery(uploadInfoList, 0);
    } else {
      _this.saveComments();
    }
  },

  /**
   * 上传评论
   */
  uploadCommentsFileQuery: function (data, queryIndex) {
    var _this = this;
    var queryData = data[queryIndex];
    var queryUrl = "";
    switch (queryData.type) {
      case "2":
        // 音频
        queryUrl = api.File_doAudioUpload;
        break;
    }
    wx.uploadFile({
      url: queryUrl,
      filePath: queryData.filePath,
      name: 'file',
      formData: {
        "type": "5"
      },
      success(res) {
        var data = JSON.parse(res.data);
        if (data.code == 200) {
          var ip = data.result.ip;
          var path = data.result.path;
          switch (queryData.type) {
            case "2":
              // 音频
              _this.setData({
                ["commentsAudio.ip"]: ip,
                ["commentsAudio.src"]: path
              })
              break;
          }
        }
      },
      fail(res) {
        // 失败
      },
      complete(res) {
        // 结束：
        if (queryIndex < data.length - 1) {
          // 图片未上传完成，继续上传
          queryIndex++;
          _this.uploadFileQuery(data, queryIndex);
        } else {
          // 上传完成，执行save请求
          _this.saveComments();
        }
      }
    })
  },

  /**
   * save评论请求
   */
  saveComments: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var saveCommentsIndex = _this.data.saveCommentsIndex;
    util.post(api.fetchToken()).then(function (res) {
      if (res.access_token != '') {
        return Promise.resolve({
          access_token: res.access_token
        });
      }
    }).then(function (res) {
      var data = {};
      data.openid = openid;
      data.access_token = res.access_token;
      data.circleid = _this.data.circleid;
      data.diaryid = _this.data.diaryInfoList[saveCommentsIndex].ordDiary.id;
      data.replyCommentsid = _this.data.replyCommentsid;
      data.mainReplyCommentsid = _this.data.mainReplyCommentsid;
      data.diaryText = _this.data.commentsTextarea;
      if (_this.data.commentsAudio.state != null && _this.data.commentsAudio.state == "2") {
        data.diaryAudio = JSON.stringify(_this.data.commentsAudio);
      }
      util.post(api.Home_SaveOrUpdateOrdDiaryCommentsApiUrl, data).then(function (res) {
        wx.hideLoading();
        _this.setData({
          isSubmitAll: false
        })
        if (res.code == 200) {
          _this.getDiaryInfoByDiaryId(saveCommentsIndex);
          _this.commentsDialogClose();
          var energyInfoResults = res.result.energyInfoResults;
          if (energyInfoResults == true) {
            _this.setData({
              diary_commones_dialog: true
            })
            setTimeout(() => {
              _this.setData({
                diary_commones_dialog: false
              })
            }, 2000);
          }
        }
      })
    })
  },

  /**
   * 清除定时器
   */
  doClearInterval: function () {
    clearInterval(recordInterval);
    recordInterval = null;
  },

  notToDiaryDetails: function () {

  },

  /**
   * 预览图片：点评
   */
  previewReviewImage: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var xindex = e.currentTarget.dataset.xindex;
    var ordReviewImageList = _this.data.diaryInfoList[index].ordReviewList[yindex].ordReviewImageList;
    var urls = [];
    var current = ordReviewImageList[xindex].ip + ordReviewImageList[xindex].url;
    for (var i = 0; i < ordReviewImageList.length; i++) {
      urls.push(ordReviewImageList[i].ip + ordReviewImageList[i].url);
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
   * 播放录音：点评详情
   */
  ordReviewBoFang: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var xindex = e.currentTarget.dataset.xindex;
    var ordReviewAudio = _this.data.diaryInfoList[index].ordReviewList[yindex].ordReviewAudioList[xindex];
    var isBoFang = ordReviewAudio.isBoFang;
    var ip = ordReviewAudio.ip;
    var name = ordReviewAudio.name;
    var currentTime = ordReviewAudio.currentTime;
    var audiourl = ordReviewAudio.url;
    var backgroundAudioManager = wx.getBackgroundAudioManager(); //获取全局唯一的背景音频管理器
    if (isBoFang == "1") {
      // 切换至暂停状态
      wx.pauseBackgroundAudio(); //暂停播放音乐
      backgroundAudioManager.pause(); //暂停播放音乐
      _this.setData({
        ["diaryInfoList[" + index + "].ordReviewList[" + yindex + "].ordReviewAudioList[" + xindex + "].isBoFang"]: 0
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio(); //暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime; //设置音乐开始时间
      backgroundAudioManager.title = name;
      backgroundAudioManager.src = ip + audiourl;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["diaryInfoList[" + index + "].ordReviewList[" + yindex + "].ordReviewAudioList[" + xindex + "].currentTime"]: 0,
          ["diaryInfoList[" + index + "].ordReviewList[" + yindex + "].ordReviewAudioList[" + xindex + "].isBoFang"]: 0
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = parseInt(backgroundAudioManager.currentTime);
        var startDate = util.digitalFormatTime(position);
        _this.setData({
          ["diaryInfoList[" + index + "].ordReviewList[" + yindex + "].ordReviewAudioList[" + xindex + "].currentTime"]: backgroundAudioManager.currentTime,
          ["diaryInfoList[" + index + "].ordReviewList[" + yindex + "].ordReviewAudioList[" + xindex + "].startDate"]: startDate
        });
      })
      _this.setData({
        ["diaryInfoList[" + index + "].ordReviewList[" + yindex + "].ordReviewAudioList[" + xindex + "].isBoFang"]: 1
      });
    }
  },

  /**
   * 评论的右侧点击显示底部的弹窗
   */
  commonsBottomShow: function (e) {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var id = e.currentTarget.dataset.id;
    var mainid = e.currentTarget.dataset.mainid;
    var nickname = e.currentTarget.dataset.nickname;
    var saveCommentsIndex = e.currentTarget.dataset.index;
    var commonsopenid = e.currentTarget.dataset.commonsopenid;
    var diaryCommentsid = e.currentTarget.dataset.deleteid;
    var isCommonsDelete = false;
    if (commonsopenid == openid) {
      isCommonsDelete = true;
    }
    _this.setData({
      commonsBottomShow: true,
      replyCommentsid: id,
      mainReplyCommentsid: mainid,
      replyCommentNickname: nickname,
      saveCommentsIndex: saveCommentsIndex,
      isCommonsDelete: isCommonsDelete,
      diaryCommentsid: diaryCommentsid
    })
  },

  /**
   * 删除评论
   */
  commentsDelete: function () {
    var _this = this;
    var replyCommentsid = _this.data.replyCommentsid;
    var saveCommentsIndex = _this.data.saveCommentsIndex;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      wx.showLoading({
        title: "删除中"
      })
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = _this.data.circleid;
        data.diaryid = _this.data.diaryInfoList[saveCommentsIndex].ordDiary.id;
        data.diaryCommentsid = _this.data.diaryCommentsid;
        util.post(api.Home_DeleteOrdDiaryCommentsApiUrl, data).then(function (res) {
          wx.hideLoading();
          if (res.code == 200) {
            _this.getDiaryInfoByDiaryId(saveCommentsIndex);
            _this.commonsBottomClose();
          }
        });
      })
    }
  },

  /**
   * 评论的右侧点击关闭底部的弹窗
   */
  commonsBottomClose: function () {
    var _this = this;
    _this.setData({
      commonsBottomShow: false,
      replyCommentsid: 0,
      mainReplyCommentsid: 0,
      replyCommentNickname: '',
      saveCommentsIndex: ''
    })
  },

  /**
   * 播放录音：评论
   */
  ordCommonsBoFang: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var xindex = e.currentTarget.dataset.xindex;
    var zindex = e.currentTarget.dataset.zindex;
    var ordCommonsAudio = {};
    if (parseInt(zindex) >= 0) {
      ordCommonsAudio = _this.data.diaryInfoList[index].commentsList[yindex].replyCommentsList[zindex].replyCommentsAudioList[xindex];
    } else {
      ordCommonsAudio = _this.data.diaryInfoList[index].commentsList[yindex].replyCommentsAudioList[xindex];
    }
    var isBoFang = ordCommonsAudio.isBoFang;
    var ip = ordCommonsAudio.ip;
    var name = ordCommonsAudio.name;
    var currentTime = ordCommonsAudio.currentTime;
    var audiourl = ordCommonsAudio.url;
    var backgroundAudioManager = wx.getBackgroundAudioManager(); //获取全局唯一的背景音频管理器
    if (isBoFang == "1") {
      // 切换至暂停状态
      wx.pauseBackgroundAudio(); //暂停播放音乐
      backgroundAudioManager.pause(); //暂停播放音乐
      if (parseInt(zindex) >= 0) {
        _this.setData({
          ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsList[" + zindex + "].replyCommentsAudioList[" + xindex + "].isBoFang"]: 0
        });
      } else {
        _this.setData({
          ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsAudioList[" + xindex + "].isBoFang"]: 0
        });
      }
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio(); ////暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime; //设置音乐开始时间
      backgroundAudioManager.title = name;
      backgroundAudioManager.src = ip + audiourl;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        if (parseInt(zindex) >= 0) {
          _this.setData({
            ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsList[" + zindex + "].replyCommentsAudioList[" + xindex + "].isBoFang"]: 0,
            ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsList[" + zindex + "].replyCommentsAudioList[" + xindex + "].currentTime"]: 0
          });
        } else {
          _this.setData({
            ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsAudioList[" + xindex + "].isBoFang"]: 0,
            ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsAudioList[" + xindex + "].currentTime"]: 0
          });
        }
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        if (parseInt(zindex) >= 0) {
          _this.setData({
            ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsList[" + zindex + "].replyCommentsAudioList[" + xindex + "].currentTime"]: backgroundAudioManager.currentTime
          });
        } else {
          _this.setData({
            ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsAudioList[" + xindex + "].currentTime"]: backgroundAudioManager.currentTime
          });
        }
      })

      if (parseInt(zindex) >= 0) {
        _this.setData({
          ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsList[" + zindex + "].replyCommentsAudioList[" + xindex + "].isBoFang"]: 1
        });
      } else {
        _this.setData({
          ["diaryInfoList[" + index + "].commentsList[" + yindex + "].replyCommentsAudioList[" + xindex + "].isBoFang"]: 1
        });
      }
    }
  },


  /**
   * 收藏或取消收藏
   */
  collectionTap: function (e) {
    var _this = this;
    var circleid = _this.data.circleid;
    var collectionUserCount = _this.data.collectionUserCount;
    var collectionTotalCount = _this.data.collectionTotalCount;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.circleid = circleid;
        data.access_token = res.access_token;
        util.post(api.Home_OperationCollectionCircleApiUrl, data).then(function (res) {
          if (collectionUserCount > 0) {
            _this.setData({
              collectionUserCount: 0,
              collectionTotalCount: parseInt(collectionTotalCount - 1),
              cancelCollectionShow: false,
              moreShow: false,
            })
          } else {
            _this.setData({
              collectionUserCount: 1,
              collectionTotalCount: parseInt(collectionTotalCount + 1),
              moreShow: false
            })
            util.showToast("已收藏","success");
          }
        })
      })
    }
  },

  /**
   * 取消收藏时弹窗
   */
  cancelCollectionShow: function () {
    var _this = this;
    _this.setData({
      cancelCollectionShow: !_this.data.cancelCollectionShow,
      moreShow: false
    })
  },

  /**
   * 底部的更多事件
   */
  moreShow: function () {
    var _this = this;
    _this.setData({
      moreShow: !_this.data.moreShow
    })
  },

  /**
   * 获取组员信息
   */
  getInterestJoin: function () {
    var _this = this;
    var data = {};
    data.circleid = _this.data.circleid;
    data.pageNum = 1;
    data.pageSize = 10;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getInterestJoinQuery(api.Home_GetInterestJoinApiUrl, data);
      })
    } else {
      _this.getInterestJoinQuery(api.Home_GetInterestJoinUrl, data);
    }
  },

  /**
   * 获取组员：请求
   */
  getInterestJoinQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var resultList = res.result.list;
        _this.setData({
          interestJoinList: resultList
        })
      }
    });
  },

  /**
   * 进入圈子详情页面
   */
  navigateToCircleInfo: function (e) {
    var _this = this;
    var circleid = e.currentTarget.dataset.circleid;
    var openid = app.globalData.logininfo.openid;
    var data = {};
    data.circleid = circleid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.userIsCircleJoinQuery(api.Home_UserIsCircleJoinApiUrl, data);
      })
    } else {
      _this.userIsCircleJoinQuery(api.Home_UserIsCircleJoinUrl, data);
    }
  },

  /**
   * 校验用户是否为已加入的圈子：请求
   */
  userIsCircleJoinQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      var userIsCircleJoin = false;
      if (res.code == 200) {
        userIsCircleJoin = res.result.userIsCircleJoin;
      }
      if (userIsCircleJoin) {
        // 已加入
        wx.navigateTo({
          url: '../circleinteraction/circleinteraction?circleid=' + data.circleid,
        })
      } else {
        // 未加入
        wx.navigateTo({
          url: '../circledetails/circledetails?circleid=' + data.circleid + "&distributionOpenid=" + _this.data.mainUser.openid,
        })
      }
    });
  },

  /**
   * 跳转到圈子互动页面
   */
  redirectToCircleinteraction: function(){
    wx.redirectTo({
      url: '../circleinteraction/circleinteraction?circleid=' + this.data.circleid,
    })
  },

  /**
   * 加入圈子
   */
  saveOrdInterestJoin: function (e) {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = _this.data.circleid;
        util.post(api.Interest_GetUserNotJoinOngoingAmount, data).then(function (res) {
          if (res.code == 200) {
            var isAmountDetail = res.result.json.isAmountDetail;
            if (isAmountDetail) {
              // 有加入信息，这时候应该弹出到团购那里
              _this.setData({
                userNotJoinOngoingAmount: res.result.json,
                ["ticket.groupbuyShowType"]: res.result.json.isOverdue ? 1 : 2
              })
              _this.groupbuyShow();
            } else {
              // 没有加入信息
              _this.saveOrdInterestJoinQuery(e);
            }
          }
        })
      })
    }
  },

  /**
   * 加入圈子
   */
  saveOrdInterestJoin2: function (e) {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = _this.data.circleid;
        util.post(api.Interest_GetUserNotJoinOngoingAmount, data).then(function (res) {
          if (res.code == 200) {
            var isAmountDetail = res.result.json.isAmountDetail;
            if (isAmountDetail) {
              // 有加入信息，这时候应该弹出到团购那里
              _this.setData({
                userNotJoinOngoingAmount: res.result.json,
                ["ticket.groupbuyShowType"]: res.result.json.isOverdue ? 1 : 2
              })
              _this.groupbuyShow();
            }
          }
        })
      })
    }
  },

  /**
   * 加入圈子：请求
   */
  saveOrdInterestJoinQuery: function(e){
    var _this = this;
    var circleid = _this.data.circleid;
    var openid = app.globalData.logininfo.openid;
    var isExperience = e.currentTarget.dataset.isexperience;
    var amountDetailsList = _this.data.amountDetails.length;
    if (isExperience == 1 || amountDetailsList <= 0) {
      // 体验圈子，或者没有票种的圈子：直接加入
      if (openid != null && openid != "") {
        // 已登录
        util.post(api.fetchToken()).then(function (res) {
          if (res.access_token != '') {
            return Promise.resolve({
              access_token: res.access_token
            });
          }
        }).then(function (res) {
          var data = {};
          data.circleid = circleid;
          data.openid = openid;
          data.isExperience = isExperience;
          data.access_token = res.access_token;
          data.invitationOpenid = _this.data.invitationOpenid;
          util.post(api.Interest_BuyAmount, data).then(function (res) {
            if (res.code == 200) {
              // 加入成功
              util.showToast("加入圈子成功", "success");
              setTimeout(function () {
                _this.redirectToCircleinteraction();
              }, 1000);
            } else {
              util.showToast(res.message, "none")
            }
          })
        })
      }
    } else {
      // 有票种，弹出票种
      _this.selectTicketShow();
    }
  },

  /**
   * 弹出选择票种的view
   */
  selectTicketShow: function () {
    var _this = this;
    _this.setData({
      ["ticket.selectTicketShow"]: true
    })
  },

  /**
   * 关闭选择票种的view
   */
  selectTicketClose: function () {
    var _this = this;
    _this.setData({
      ["ticket.selectTicketShow"]: false,
      ["ticket.next1_submit"]: false,
    })
  },

  /**
   * 票种选中事件
   */
  amountDetailsClick: function(e){
    var _this = this;
    var index = e.currentTarget.dataset.index;
    if (index != _this.data.ticket.selectTicketIndex){
      var amountDetails = _this.data.amountDetails;
      var buyNumber = amountDetails[index].buyNumber;
      var amountDetailsId = amountDetails[index].id;
      var selectNumber = 0
      if (buyNumber > 0) {
        selectNumber = 1;
      }
      _this.setData({
        ["ticket.selectTicketIndex"]: index
      })

      // 需要调用后台接口计算价格
      _this.calculationTicketPrice(selectNumber, amountDetailsId, true);
    }
  },

  /**
   * 加入圈子（都不是体验圈子）
   */
  saveOrdInterestJoin_real: function () {
    var _this = this;
    _this.setData({
      ["ticket.next1_submit"]: true
    })
    var circleid = _this.data.circleid;
    var openid = app.globalData.logininfo.openid;
    var selectTicketIndex = _this.data.ticket.selectTicketIndex;
    var amountDetailsId = _this.data.amountDetails[selectTicketIndex].id;
    var preferentialSettings = _this.data.amountDetails[selectTicketIndex].preferentialSettings;
    var userInfo = _this.data.ticket.userInfo;
    var selectNumber = _this.data.ticket.selectNumber;
    var amountDetailsGroupbuyId = _this.data.ticket.amountDetailsGroupbuyId;
    var shareAmountDetailsGroupbuyId = _this.data.shareAmountDetailsGroupbuyId;
    
    if (selectNumber == null || amountDetailsId == null || parseInt(selectNumber) <= 0 || parseInt(amountDetailsId) <= 0) {
      util.dialogAlert("请选择票种信息");
      return;
    }
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.circleid = circleid;
        data.openid = openid;
        data.isExperience = 0;
        data.amountDetailsId = amountDetailsId;
        data.buySize = selectNumber;
        data.access_token = res.access_token;
        data.invitationOpenid = _this.data.invitationOpenid;
        data.distributionOpenid = _this.data.distributionOpenid;
        if (shareAmountDetailsGroupbuyId > 0) {
          data.amountDetailsGroupbuyId = shareAmountDetailsGroupbuyId;
        }else{
          data.amountDetailsGroupbuyId = amountDetailsGroupbuyId;
        }
        if (userInfo.length > 0){
          data.joinUserInfo = JSON.stringify(userInfo);
        }
        util.post(api.Interest_BuyAmount, data).then(function (res) {
          if (res.code == 200) {
            var buyJoinState = res.result.buyJoinState;
            var json = res.result.json;
            var orderNum = json.orderNum;
            var totalMoney = json.totalMoney;
            if (buyJoinState == 1){
              // 不需要支付
              if (preferentialSettings == 1){
                // 团购订单，显示邀请好友页面
                _this.selectTicketClose();
                _this.userInfoClose();
                // 团购订单，显示邀请好友页面：调用此代码，里面有进行弹窗的
                _this.saveOrdInterestJoin2();
                //_this.groupbuyShow();
              }else{
                // 直接进入订单页面
                _this.navigateToOrder(orderNum);
              }
            } else if (buyJoinState == 2){
              // 需要支付金额，再调用支付接口
              _this.wechatCallbackBusiness(orderNum, totalMoney);
            }
          } else {
            util.showToast(res.message, "none");
            _this.setData({
              ["ticket.next1_submit"]: false
            })
          }
        })
      })
    }
  },

  /**
   * 微信支付回调：这个应该是支付后自动触发，但是开发阶段，就代码触发
   */
  wechatCallbackBusiness: function (orderNum, totalMoney){
    // 调用支付，支付成功之后，判断是否是团购订单，是团购，则弹窗
    var _this = this;
    var param = {};
    param.orderNum = orderNum;
    param.actualPrice = totalMoney;
    param.outTradeNo = new Date().getTime();
    util.post(api.Interest_WechatCallback, param, "application/x-www-form-urlencoded;charset=UTF-8").then(function (res) {
      wx.showLoading({
        title: '支付中',
      })
      getOrderByOrderNumInterval = setInterval(function () {
        _this.getOrderByOrderNum(orderNum);
      }, 1000);
    })
  },

  /**
   * 通过订单号获取订单信息
   */
  getOrderByOrderNum: function (orderNum){
    var _this = this;
    var openid = _this.data.logininfo.openid;
    util.post(api.fetchToken()).then(function (res1) {
      if (res1.access_token != '') {
        return Promise.resolve({
          access_token: res1.access_token
        });
      }
    }).then(function (res2) {
      var param = {};
      param.openid = openid;
      param.orderNum = orderNum;
      param.access_token = res2.access_token;
      util.post(api.Interest_GetOrderByOrderNum, param).then(function (res) {
        if(res.code == 200){
          clearInterval(getOrderByOrderNumInterval);
          var order = res.result.obj;
          if (order.orderStatus == 100) {
            var selectTicketIndex = _this.data.ticket.selectTicketIndex;
            var preferentialSettings = _this.data.amountDetails[selectTicketIndex].preferentialSettings;
            if (preferentialSettings == 1) {
              // 团购订单，显示邀请好友页面：调用此代码，里面有进行弹窗的
              _this.selectTicketClose();
              _this.userInfoClose();
              _this.saveOrdInterestJoin2();
            } else {
              // 直接进入订单页面
              _this.navigateToOrder(orderNum);
            }
          }
        }
        wx.hideLoading();
      })
    })
  },

  /**
   * 进入订单页面
   */
  navigateToOrder: function (orderNum){
    var _this = this;
    // 关闭所有弹窗
    _this.closeAllShow();
    wx.navigateTo({
      url: "../../../../../../interest/pages/interest/order/order?orderNum=" + orderNum,
    })
  },

  /**
   * 关闭所有的订单加入弹窗
   */
  closeAllShow: function(){
    var _this = this;
    // 关闭所有弹窗
    _this.groupbuyClose();
    _this.selectTicketClose();
    _this.orangeShellPayClose();
    _this.userInfoClose();
    _this.selectTicketClose();
    _this.setData({
      ticket: { "selectTicketShow": false, "userInfoShow": false, "orangeShellPayShow": false, "groupbuyShow": false, "orangeShellPayProgress": 1, "selectTicketIndex": 0, "selectNumber": 0, "orangeShell": 0, "totalMoney": 0, "next1_submit": false, "groupbuyDialogShow": false, "userInfo": [], "amountDetailsGroupbuyId": "", "groupbuyShowType": 0 }
    })
  },

  /**
   * 修改圈子的预览次数
   */
  addIspreview: function () {
    var _this = this;
    var data = {};
    data.circleid = _this.data.circleid;
    util.post(api.Interest_addIspreview, data).then(function (res) { })
  },

  /**
   * 成长：打开弹窗
   */
  seedDialogShow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var seedDialog = _this.data.seedDialog;
    seedDialog.show = true;
    seedDialog.index = index;
    seedDialog.diaryInfo = _this.data.diaryInfoList[index];
    _this.setData({
      seedDialog: seedDialog
    })
  },

  /**
   * 成长：关闭弹窗
   */
  seedDialogClose: function () {
    var _this = this;
    var seedDialog = { "show": false, "index": "", "seedRulesDialogShow": false, "diaryInfo": {} };
    _this.setData({
      seedDialog: seedDialog
    })
  },

  /**
   * 种子法则
   */
  seedRulesDialogShow: function () {
    var _this = this;
    _this.setData({
      ["seedDialog.seedRulesDialogShow"]: !_this.data.seedDialog.seedRulesDialogShow
    })
  },

  /**
   * 评论的弹窗打开
   */
  commentsDialogShow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      commentsDialogShow: true,
      saveCommentsIndex: index,
      commonsBottomShow: false
    })
  },

  /**
   * 点评弹窗
   */
  commentsShow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      reviewBottomIndex: index,
      review_diary: _this.data.diaryInfoList[index],
      reviewBottomShow: false,
      reviewDialogShow: true
    })
  },

  /**
   * 点评的星星点击事件
   */
  reviewScoreTap: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var imageList = _this.data.reviewImageList.imageList;
    var clickNumber = imageList[index].clickNumber;
    for (var i = 0; i < imageList.length; i++) {
      imageList[i].clickNumber = 0;
    }
    for (var i = 0; i < index; i++) {
      imageList[i].clickNumber = 2;
    }
    if (clickNumber < 2) {
      imageList[index].clickNumber = clickNumber + 1;
    } else {
      imageList[index].clickNumber = 0;
    }
    var totalClickNumber = 0;
    for (var i = 0; i < imageList.length; i++) {
      totalClickNumber = totalClickNumber + imageList[i].clickNumber;
    }
    var reviewImageList = { "imageList": imageList, "totalScore": totalClickNumber };
    _this.setData({
      reviewImageList: reviewImageList
    })
  },

  /**
   * 点评的textarea的焦点移入事件
   */
  reviewTextareaCheckYes: function (e) {
    var _this = this;
    var reviewTextareaShow = _this.data.reviewTextareaShow;
    _this.setData({
      reviewTextareaShow: true
    })
  },

  /**
   * 点评的texteare的输入事件
   */
  reviewTextareaInput: function (e) {
    var _this = this;
    var reviewTextarea = e.detail.value;
    _this.setData({
      reviewTextarea: reviewTextarea
    })
  },

  /**
   * 点评的textarea的焦点移出事件
   */
  reviewTextareaCheckNo: function (e) {
    var _this = this;
    var isSwitchEmoji = false;
    if (e.detail != null && e.detail.isSwitchEmoji != null) {
      isSwitchEmoji = e.detail.isSwitchEmoji;
    }
    if (!isSwitchEmoji) {
      var reviewTextareaShow = _this.data.reviewTextareaShow;
      _this.setData({
        reviewTextareaShow: false
      })
    }
  },

  /**
   * 播放或暂停动作
   */
  reviewAudioBoFang: function (e) {
    var _this = this;
    var src = _this.data.reviewAudio.src;
    var title = _this.data.reviewAudio.title;
    var currentTime = _this.data.reviewAudio.currenttime;
    var isBoFang = _this.data.reviewAudio.isBoFang;
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (isBoFang == "1") {
      // 切换至暂停状态
      backgroundAudioManager.pause();//暂停播放音乐
      _this.setData({
        ["reviewAudio.isBoFang"]: "0"
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio();//暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime;//设置音乐开始时间
      backgroundAudioManager.title = title;
      backgroundAudioManager.src = src;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["reviewAudio.currentTime"]: 0,
          ["reviewAudio.isBoFang"]: "0",
          ["reviewAudio.startDate"]: "00:00"
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = Math.round(backgroundAudioManager.currentTime);
        var voiceStartDate = util.digitalFormatTime(position);
        _this.setData({
          ["reviewAudio.currentTime"]: backgroundAudioManager.currentTime,
          ["reviewAudio.startDate"]: voiceStartDate
        });
      })

      _this.setData({
        ["reviewAudio.isBoFang"]: "1"
      });
    }
  },

  /**
   * 删除录音：点评
   */
  deleteReviewRecorder: function () {
    var _this = this;
    _this.doClearInterval();
    recorderManager.stop();
    var isupload = _this.data.reviewAudio.isupload;
    var reviewAudio = {};
    reviewAudio.isupload = isupload;
    if (!isupload) {
      // 删除的是已存数据库的
      reviewAudio.isDelete = true;
    }
    _this.setData({
      reviewAudio: reviewAudio
    })
  },

  /**
   * 清空录音：点评
   */
  clearReviewRecorder: function () {
    var _this = this;
    _this.setData({
      ["reviewAudio.isVoiceDialogShow"]: false
    })
    _this.doClearInterval();
    recorderManager.stop();

    setTimeout(function () {
      _this.reviewAudioTap();
    }, 100)
  },

  /**
   * 暂停录音：点评
   */
  reviewPauseRecorder: function (e) {
    var _this = this;
    _this.setData({
      ["reviewAudio.playState"]: "2"
    });
    recorderManager.pause();
    _this.doClearInterval();
  },

  /**
   * 继续录音：点评
   */
  reviewResumeRecorder: function (e) {
    var _this = this;
    _this.setData({
      ["reviewAudio.playState"]: "1"
    })
    recorderManager.resume();
    _this.doReviewRecordInterval();
  },

  /**
   * 停止录音：点评
   */
  reviewStopRecorder: function (e) {
    var _this = this;
    recorderManager.stop();
    recorderManager.onStop((res) => {
      _this.reviewStopRecorderExecute(res);
    });
  },

  /**
   * 删除点评图片
   */
  deleteReviewImage: function () {
    var _this = this;
    var isupload = _this.data.reviewImage.isupload;
    var reviewImage = {};
    reviewImage.isupload = isupload;
    if (!isupload) {
      // 删除的是已存数据库的
      reviewImage.isDelete = true;
    }
    _this.setData({
      reviewImage: reviewImage
    })
  },

  /**
   * 点评图片
   */
  reviewImageTap: function () {
    var _this = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        var reviewImage = {};
        reviewImage = res.tempFiles[0];
        reviewImage.isupload = true;
        _this.setData({
          reviewImage: reviewImage
        })
      }
    })
  },

  /**
   * 点评录音
   */
  reviewAudioTap: function () {
    var _this = this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.record']) {
          // 未授权
          wx.authorize({
            scope: 'scope.record',
            success() {
              _this.reviewAudioStart();
            },
            fail: function () {
              // 拒绝授权
              _this.setData({
                audioOauhRefusedDialogShow: true
              })
            }
          })
        } else {
          // 已授权
          _this.reviewAudioStart();
        }
      }
    })
  },

  /**
   * 开始录音：点评
   */
  reviewAudioStart: function () {
    var _this = this;
    var reviewAudio = {};
    reviewAudio.isupload = true;
    reviewAudio.state = "1";// 1正在录音  2录音完毕（state==2的时候，playState无效）
    reviewAudio.playState = "1";// 1正常录音  2暂停录音
    reviewAudio.isBoFang = "0";
    reviewAudio.totalTime = 0;
    reviewAudio.totalDate = "00:00";
    reviewAudio.isVoiceDialogShow = true;
    _this.setData({
      reviewAudio: reviewAudio
    })

    const recorderOptions = {
      duration: util.getAudioFileMaxTime("diaryReview"),//指定录音的时长，单位 ms，默认十分钟
      format: 'mp3'
    }
    //开始录音
    recorderManager.start(recorderOptions);

    // 定时器计算录音时间
    _this.doReviewRecordInterval();

    // 录音结束
    recorderManager.onStop((res) => {
      _this.reviewStopRecorderExecute(res);
    });

    // 录音中断
    recorderManager.onInterruptionBegin((res) => {
      recorderManager.stop();
      _this.reviewStopRecorderExecute(res);
    });
  },

  /**
   * 停止录音后的业务代码：点评
   */
  reviewStopRecorderExecute: function (tempFile) {
    var _this = this;
    _this.doClearInterval();
    var isVoiceDialogShow = _this.data.reviewAudio.isVoiceDialogShow;
    if (isVoiceDialogShow) {
      var totalTime = parseInt(tempFile.duration / 1000);
      var reviewAudio = _this.data.reviewAudio;
      reviewAudio.state = "2";
      reviewAudio.src = tempFile.tempFilePath;
      reviewAudio.title = "录音音频";
      reviewAudio.currentTime = 0;
      reviewAudio.totalTime = totalTime;
      reviewAudio.fileSize = tempFile.fileSize;
      reviewAudio.startDate = "00:00";
      reviewAudio.totalDate = util.digitalFormatTime(totalTime);
      reviewAudio.isBoFang = "0";
      _this.setData({
        reviewAudio: reviewAudio
      })
    }
  },

  /**
   * 定时器计算录音时间
   */
  doReviewRecordInterval: function () {
    var _this = this;
    if (recordInterval == null) {
      recordInterval = setInterval(function () {
        var reviewAudio = _this.data.reviewAudio;
        var totalTime = reviewAudio.totalTime + 1;
        var totalDate = util.digitalFormatTime(totalTime);
        _this.setData({
          ["reviewAudio.totalTime"]: totalTime,
          ["reviewAudio.totalDate"]: totalDate
        });
      }, 1000);
    }
  },

  /**
   * 添加快捷语弹窗的显示
   */
  quickLanguageShow: function () {
    var _this = this;
    var quickLanguageShow = _this.data.quickLanguageShow;
    _this.setData({
      quickLanguageShow: true
    })
  },

  /**
   * 快捷评语选中事件
   */
  reviewQuickCenterTap: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var text = _this.data.reviewQuickList[index].text;
    var reviewTextarea = _this.data.reviewTextarea;
    if (reviewTextarea.length > 0) {
      text = reviewTextarea + "，" + text;
    }
    _this.setData({
      reviewTextarea: text
    })
  },

  /**
   * 快捷语的list右侧的点点点选中事件
   */
  selectReviewQuick: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      selectReviewQuickIndex: index,
      quickLanguageBottomShow: true
    })
  },

  /**
   * 取消点评
   */
  closeReview: function () {
    var _this = this;
    _this.deleteCommentsRecorder();
    _this.setData({
      review_diary: {},
      reviewDialogShow: false,
      reviewImageList: { "imageList": [{ "clickNumber": 0 }, { "clickNumber": 0 }, { "clickNumber": 0 }, { "clickNumber": 0 }, { "clickNumber": 0 }], "totalScore": 0 },
      reviewTextarea: '',
      reviewAudio: {},
      reviewImage: {},
      reviewBottomIndex: '',
      reviewBottomYIndex: '',
      ordReviewId: ''
    })
  },

  /**
   * 发表点评
   */
  submitReview: function () {
    var _this = this;
    var totalScore = _this.data.reviewImageList.totalScore;
    var reviewTextarea = _this.data.reviewTextarea;
    var reviewAudio = _this.data.reviewAudio;
    var reviewImage = _this.data.reviewImage;
    if (!(reviewTextarea.length > 0 || (reviewAudio.state != null && reviewAudio.state.length > 0) || (reviewImage.path != null && reviewImage.path.length > 0))) {
      util.dialogAlert("评论内容不能为空");
      return false;
    } else if (reviewAudio.state != null && reviewAudio.state == "1") {
      util.dialogAlert("正在录制音频中");
      return false;
    }
    wx.showLoading({
      title: '保存中',
    })
    _this.setData({
      isSubmitAll: false
    })
    var uploadInfoList = [];
    if (reviewImage.path != null && reviewImage.path.length > 0 && reviewImage.isupload) {
      var uploadInfo = {};
      uploadInfo.type = "1";// 类型:1图片  2音频  3视频
      uploadInfo.filePath = reviewImage.path;
      uploadInfoList.push(uploadInfo);
    }
    if (reviewAudio.state != null && reviewAudio.state == "2" && reviewAudio.isupload) {
      var uploadInfo = {};
      uploadInfo.type = "2";// 类型:1图片  2音频  3视频
      uploadInfo.filePath = reviewAudio.src;
      uploadInfoList.push(uploadInfo);
    }
    if (uploadInfoList.length > 0) {
      // 开始请求:要先上传
      _this.uploadFileQuery(uploadInfoList, 0);
    } else {
      _this.saveReview();
    }
  },

  /**
   * 上传
   */
  uploadFileQuery: function (data, queryIndex) {
    var _this = this;
    var queryData = data[queryIndex];
    var queryUrl = "";
    switch (queryData.type) {
      case "1":
        // 图片
        queryUrl = api.File_doImageUpload;
        break;
      case "2":
        // 音频
        queryUrl = api.File_doAudioUpload;
        break;
    }
    wx.uploadFile({
      url: queryUrl,
      filePath: queryData.filePath,
      name: 'file',
      formData: {
        "type": "4"
      },
      success(res) {
        var data = JSON.parse(res.data);
        if (data.code == 200) {
          var ip = data.result.ip;
          var path = data.result.path;
          switch (queryData.type) {
            case "1":
              // 图片
              _this.setData({
                ["reviewImage.ip"]: ip,
                ["reviewImage.path"]: path
              })
              break;
            case "2":
              // 音频
              _this.setData({
                ["reviewAudio.ip"]: ip,
                ["reviewAudio.src"]: path
              })
              break;
          }
        }
      },
      fail(res) {
        // 失败
      },
      complete(res) {
        // 结束：
        if (queryIndex < data.length - 1) {
          // 图片未上传完成，继续上传
          queryIndex++;
          _this.uploadFileQuery(data, queryIndex);
        } else {
          // 上传完成，执行save请求
          _this.saveReview();
        }
      }
    })
  },

  /**
   * save点评请求
   */
  saveReview: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    util.post(api.fetchToken()).then(function (res) {
      if (res.access_token != '') {
        return Promise.resolve({
          access_token: res.access_token
        });
      }
    }).then(function (res) {
      var data = {};
      data.openid = openid;
      data.access_token = res.access_token;
      data.circleid = _this.data.circleid;
      data.ordDiaryid = _this.data.review_diary.ordDiary.id;
      data.ordReviewScore = _this.data.reviewImageList.totalScore;
      data.ordReviewText = _this.data.reviewTextarea;
      data.ordReviewId = _this.data.ordReviewId;
      if (_this.data.reviewAudio.isupload || _this.data.reviewAudio.isDelete) {
        data.ordReviewAudio = JSON.stringify(_this.data.reviewAudio);
      } else {
        data.ordReviewAudio = "";
      }
      if (_this.data.reviewImage.isupload || _this.data.reviewImage.isDelete) {
        data.ordReviewImage = JSON.stringify(_this.data.reviewImage);
      } else {
        data.ordReviewImage = "";
      }
      util.post(api.Home_SaveOrUpdateOrdReviewApiUrl, data).then(function (res) {
        wx.hideLoading();
        _this.setData({
          isSubmitAll: false
        })
        if (res.code == 200) {
          _this.getDiaryInfoByDiaryId(_this.data.reviewBottomIndex);
          _this.closeReview();
          var energyInfoResults = res.result.energyInfoResults;
          if (energyInfoResults == true) {
            _this.setData({
              diary_review_dialog: true
            })
            setTimeout(() => {
              _this.setData({
                diary_review_dialog: false
              })
            }, 2000);
          }
        }
      })
    })
  },

  /**
   * 快捷语的textarea输入事件
   */
  ordReviewQuickTextInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    _this.setData({
      ordReviewQuickText: value,
      ordReviewQuickTextLength: value.length
    })
  },

  /**
   * 添加快捷语弹窗的关闭
   */
  quickLanguageClose: function () {
    var _this = this;
    var quickLanguageShow = _this.data.quickLanguageShow;
    _this.setData({
      quickLanguageShow: false,
      ordReviewQuickText: '',
      ordReviewQuickId: '',
      selectReviewQuickIndex: '',
      ordReviewQuickTextLength: 0
    })
  },

  /**
   * 获取快捷语信息
   */
  getOrdReviewQuick: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        util.post(api.Home_GetOrdReviewQuickApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var reviewQuickList = res.result.list;
            _this.setData({
              reviewQuickList: reviewQuickList
            })
          }
        })
      })
    }
  },

  /**
   * 快捷语置顶
   */
  quickLanguagePlacedTop: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var index = _this.data.selectReviewQuickIndex;
    var ordReviewQuickId = _this.data.reviewQuickList[index].id;
    var isPlacedtop = _this.data.reviewQuickList[index].isPlacedtop;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.ordReviewQuickId = ordReviewQuickId;
        data.isPlacedtop = isPlacedtop == 0 ? "1" : "0";
        data.access_token = res.access_token;
        util.post(api.Home_SaveOrUpdateReviewQuickApiUrl, data).then(function (res) {
          _this.getOrdReviewQuick();
          _this.quickLanguageBottomClose();
        })
      })
    }
  },

  /**
   * 删除快捷语
   */
  deleteOrdReviewQuick: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var index = _this.data.selectReviewQuickIndex;
    var ordReviewQuickId = _this.data.reviewQuickList[index].id;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.ordReviewQuickId = ordReviewQuickId;
        data.access_token = res.access_token;
        util.post(api.Home_DeleteOrdReviewQuickApiUrl, data).then(function (res) {
          if (res.code == 200) {
            _this.setData({
              quickLanguageBottomShow: false,
              selectReviewQuickIndex: ''
            })
            _this.getOrdReviewQuick();
          }
        })
      })
    }
  },

  /**
  * 添加快捷语弹窗的隐藏
  */
  quickLanguageBottomClose: function () {
    var _this = this;
    _this.setData({
      quickLanguageBottomShow: false,
      selectReviewQuickIndex: '',
      ordReviewQuickId: ''
    })
  },

  /**
   * 添加快捷语弹窗的显示：编辑
   */
  quickLanguageShow2: function () {
    var _this = this;
    var quickLanguageShow = _this.data.quickLanguageShow;
    var index = _this.data.selectReviewQuickIndex;
    var ordReviewQuickId = _this.data.reviewQuickList[index].id;
    var ordReviewQuickText = _this.data.reviewQuickList[index].text;
    _this.setData({
      quickLanguageBottomShow: false,
      quickLanguageShow: true,
      ordReviewQuickText: ordReviewQuickText,
      ordReviewQuickTextLength: ordReviewQuickText.length,
      ordReviewQuickId: ordReviewQuickId,
      selectReviewQuickIndex: ''
    })
  },

  /**
   * 保存或者删除评语
   */
  saveOrUpdateReviewQuick: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var ordReviewQuickId = _this.data.ordReviewQuickId;
    var ordReviewQuickText = _this.data.ordReviewQuickText;
    if (openid != null && openid != "" && ordReviewQuickText.length > 0) {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.ordReviewQuickId = ordReviewQuickId;
        data.ordReviewQuickText = ordReviewQuickText;
        data.access_token = res.access_token;
        util.post(api.Home_SaveOrUpdateReviewQuickApiUrl, data).then(function (res) {
          _this.getOrdReviewQuick();
          _this.quickLanguageClose();
        })
      })
    }
  },

  /**
   * 置顶加精或者取消加精
   */
  updateDiaryPlacedtop: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var diaryOperationShowInfo = _this.data.diaryOperationShowInfo;
        var ordDiaryid = diaryOperationShowInfo.ordDiaryid;
        var circleid = _this.data.circleid;
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = circleid;
        data.ordDiaryid = ordDiaryid;
        util.post(api.Home_UpdateDiaryPlacedtopApiUrl, data).then(function (res) {
          if (res.code == 200) {
            _this.setData({
              ["diaryInfoList[" + diaryOperationShowInfo.index + "].ordDiary.isPlacedtop"]: res.result.count
            })
            _this.diaryOperationClose();
          }
        })
      })
    }
  },

  /**
   * 设置分组
   */
  setUpGroup: function () {
    var _this = this;
    var groupList = _this.data.groupList;
    var updateGroupid = _this.data.diaryOperationShowInfo.diaryInfo.ordInterestJoin.groupid;
    if (groupList.length > 0) {
      // 有分组，展示分组
      _this.setData({
        diaryOperationShow: false,
        groupingDialogShow: true,
        updateGroupid: updateGroupid
      })
    } else {
      // 无分组
      _this.diaryOperationClose();
      _this.setData({
        groupingEmptyDialogShow: true
      })
    }
  },

  /**
   * 删除弹窗：展开
   */
  deleteDiaryDialogShow: function () {
    var _this = this;
    _this.setData({
      deleteDiaryDialogShow: true,
      diaryOperationShow: false
    })
  },

  /**
   * 获取分组信息
   */
  getGroup: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.circleid = circleid;
        data.openid = openid;
        data.access_token = res.access_token;
        util.post(api.Home_GetGroupApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var list = res.result.list;
            _this.setData({
              groupList: list
            })
          }
        });
      })
    }
  },

  /**
   * 跳转到分组的页面
   */
  navigateToGroup: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var index = _this.data.diaryOperationShowInfo.index;
    _this.setData({
      otherPageIndex: index
    })
    wx.navigateTo({
      url: '../circleinteraction/group/group?circleid=' + circleid,
    })
  },

  /**
   * 成员设置分组选中事件
   */
  groupListBindTap: function (e) {
    var _this = this;
    var updateGroupid = e.currentTarget.dataset.id;
    _this.setData({
      updateGroupid: updateGroupid
    })
  },

  /**
   * 设置分组提交
   */
  groupingDialogConfirm: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var updateGroupid = _this.data.updateGroupid;
        var diaryOperationShowInfo = _this.data.diaryOperationShowInfo;
        var joinid = diaryOperationShowInfo.diaryInfo.ordInterestJoin.joinid;
        var data = {};
        data.joinid = joinid;
        data.groupid = updateGroupid;
        data.circleid = _this.data.circleid;
        data.openid = openid;
        data.access_token = res.access_token;
        util.post(api.Home_UpdateJoinUserInfoApiUrl, data).then(function (res) {
          if (res.code == 200) {
            _this.getDiaryInfoByDiaryId(diaryOperationShowInfo.index);
            _this.diaryOperationClose();
            _this.getGroup();
          }
        })
      })
    }
  },

  /**
   * 无分组弹窗关闭
   */
  groupingEmptyDialogClose: function () {
    var _this = this;
    _this.setData({
      groupingEmptyDialogShow: false
    })
  },

  /**
   * 无分组弹窗确定
   */
  groupingEmptyDialogConfirm: function () {
    var _this = this;
    _this.setData({
      groupingEmptyDialogShow: false
    })
    _this.navigateToGroup();
  },

  /**
   * 删除弹窗：关闭
   */
  deleteDiaryDialogClose: function () {
    var _this = this;
    _this.setData({
      deleteDiaryDialogShow: false,
      diaryOperationShow: false,
      diaryOperationShowInfo: {}
    })
  },

  /**
   * 删除弹窗：提交
   */
  deleteDiaryDialogConfirm: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var diaryInfoList = _this.data.diaryInfoList;
    var diaryOperationShowInfo = _this.data.diaryOperationShowInfo;
    var index = diaryOperationShowInfo.index;
    var ordDiaryid = diaryOperationShowInfo.ordDiaryid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.ordDiaryid = ordDiaryid;
        data.circleid = _this.data.circleid;
        util.post(api.Home_DeleteDiaryByDiaryIdApiUrl, data).then(function (res) {
          if (res.code == 200) {
            diaryInfoList.splice(index, 1);
            _this.setData({
              diaryInfoList: diaryInfoList
            })
            _this.deleteDiaryDialogClose();
          }
        })
      })
    }
  },

  /**
   * 点评底部的的弹出显示
   */
  reviewBottomShow: function (e) {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var ordReviewOpenid = _this.data.diaryInfoList[index].ordReviewList[yindex].ordReview.openid;
    var thisInterestJoinUser = _this.data.thisInterestJoinUser;
    var reviewBottomEditorAndDeleteIsShow = false;
    if (thisInterestJoinUser.identitytype == 1 || thisInterestJoinUser.identitytype == 2 || thisInterestJoinUser.identitytype == 3) {
      reviewBottomEditorAndDeleteIsShow = true;
    }
    if (ordReviewOpenid == openid) {
      reviewBottomEditorAndDeleteIsShow = true;
    }
    _this.setData({
      reviewBottomShow: true,
      reviewBottomIndex: index,
      reviewBottomYIndex: yindex,
      reviewBottomEditorAndDeleteIsShow: reviewBottomEditorAndDeleteIsShow
    })
  },

  /**
   * 编辑新点评
   */
  reviewBottomEditor: function (e) {
    var _this = this;
    var imageList = _this.data.reviewImageList.imageList;
    var index = _this.data.reviewBottomIndex;
    var yindex = _this.data.reviewBottomYIndex;
    var review_diary = _this.data.diaryInfoList[index];
    var reviewBottomInfo = review_diary.ordReviewList[yindex];
    var ordReview = reviewBottomInfo.ordReview;
    var ordReviewAudioList = reviewBottomInfo.ordReviewAudioList;
    var ordReviewImageList = reviewBottomInfo.ordReviewImageList;
    var score = ordReview.score;
    var ordReviewId = ordReview.id;
    var reviewTextarea = ordReview.text;
    var scoreIndex = 0;
    var dyScore = 0;
    if (score > 0) {
      if (score % 2 == 0) {
        scoreIndex = score / 2;
      } else {
        dyScore = 1;
        scoreIndex = (score - 1) / 2;
      }
    }
    for (var i = 0; i < imageList.length; i++) {
      imageList[i].clickNumber = 0;
    }
    for (var i = 0; i < scoreIndex; i++) {
      imageList[i].clickNumber = 2;
    }
    if (dyScore > 0) {
      imageList[scoreIndex].clickNumber = 1;
    }
    var reviewImageList = { "imageList": imageList, "totalScore": score };
    var reviewAudio = {};
    var reviewImage = {};
    if (ordReviewAudioList.length > 0) {
      var ordReviewAudio = ordReviewAudioList[0];
      reviewAudio.currentTime = 0;
      reviewAudio.isBoFang = 0;
      reviewAudio.isVoiceDialogShow = true;
      reviewAudio.isupload = false;
      reviewAudio.playState = "1";
      reviewAudio.src = ordReviewAudio.ip + ordReviewAudio.url;
      reviewAudio.startDate = "00:00";
      reviewAudio.state = "2";
      reviewAudio.title = ordReviewAudio.name;
      reviewAudio.totalDate = ordReviewAudio.totalDate;
      reviewAudio.totalTime = ordReviewAudio.totalTime;
    }
    if (ordReviewImageList.length > 0) {
      var ordReviewImage = ordReviewImageList[0];
      reviewImage.path = ordReviewImage.ip + ordReviewImage.url;
      reviewImage.isupload = false;
    }
    _this.setData({
      reviewImageList: reviewImageList,
      review_diary: review_diary,
      reviewBottomShow: false,
      reviewDialogShow: true,
      reviewTextarea: reviewTextarea,
      reviewAudio: reviewAudio,
      reviewImage: reviewImage,
      ordReviewId: ordReviewId
    })
  },

  /**
   * 删除点评弹窗
   */
  reviewBottomDelete: function () {
    var _this = this;
    _this.setData({
      reviewBottomShow: false,
      reviewBottomDeleteShow: true
    })
  },

  /**
   * 点评底部的的弹出关闭
   */
  reviewBottomClose: function (e) {
    var _this = this;
    _this.setData({
      reviewBottomShow: false,
      reviewBottomIndex: '',
      reviewBottomYIndex: '',
      reviewBottomEditorAndDeleteIsShow: false
    })
  },

  /**
   * 删除点评取消
   */
  reviewBottomDeleteClose: function () {
    var _this = this;
    _this.setData({
      reviewBottomIndex: '',
      reviewBottomYIndex: '',
      reviewBottomDeleteShow: false
    })
  },

  /**
   * 删除点评确定
   */
  reviewBottomDeleteSuccess: function () {
    var _this = this;
    var openid = _this.data.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var index = _this.data.reviewBottomIndex;
        var yindex = _this.data.reviewBottomYIndex;
        var review_diary = _this.data.diaryInfoList[index];
        var ordDiaryid = review_diary.ordReviewList[yindex].ordReview.diaryId;
        var ordReviewId = review_diary.ordReviewList[yindex].ordReview.id;
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.circleid = _this.data.circleid;
        data.ordDiaryid = ordDiaryid;
        data.ordReviewId = ordReviewId;
        util.post(api.Home_DeleteOrdReviewApiUrl, data).then(function (res) {
          if (res.code == 200) {
            _this.setData({
              reviewBottomIndex: '',
              reviewBottomDeleteShow: false
            })
            _this.getDiaryInfoByDiaryId(index);
          }
        })
      })
    }
  },

  /**
   * 使用微信内置地图查看位置
   */
  wxGetLocation: function (e) {
    var name = e.currentTarget.dataset.name;
    var address = e.currentTarget.dataset.address;
    var latitude = e.currentTarget.dataset.latitude;
    var longitude = e.currentTarget.dataset.longitude;
    wx.openLocation({
      latitude: latitude,//要去的纬度-地址
      longitude: longitude,//要去的经度-地址
      name: name,
      address: address
    })
  },

  /**
   * 预览图片：圈子详情
   */
  previewImageInterest: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var urls = [];
    var current = albumInfo[index].ip + albumInfo[index].imageurl;
    for (var i = 0; i < albumInfo.length; i++) {
      if (albumInfo[i].infoType == 2) {
        urls.push(albumInfo[i].ip + albumInfo[i].imageurl);
      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
   * 播放或暂停动作：整个详情
   */
  voiceBoFang_interest: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var boFangImage = albumInfo[index].boFangImage;
    var ip = albumInfo[index].ip;
    var name = albumInfo[index].name;
    var currentTime = albumInfo[index].currentTime;
    var audiourl = albumInfo[index].audiourl;
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      // 切换至暂停状态
      wx.pauseBackgroundAudio();//暂停播放音乐
      backgroundAudioManager.pause();//暂停播放音乐
      _this.setData({
        ["albumInfo[" + index + "].boFangImage"]: api.AudioNoBoFangImage_Name
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio();////暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime;//设置音乐开始时间
      backgroundAudioManager.title = name;
      backgroundAudioManager.src = ip + audiourl;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["albumInfo[" + index + "].startDate"]: "00:00",
          ["albumInfo[" + index + "].currentTime"]: 0,
          ["albumInfo[" + index + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = parseInt(backgroundAudioManager.currentTime);
        var startDate = util.digitalFormatTime(position);
        _this.setData({
          ["albumInfo[" + index + "].currentTime"]: backgroundAudioManager.currentTime,
          ["albumInfo[" + index + "].startDate"]: startDate
        });
      })
      _this.setData({
        ["albumInfo[" + index + "].boFangImage"]: api.AudioBoFangImage_Name
      });
    }
  },

  /**
   * 播放音乐（滚动条事件）：整个详情
   */
  voiceSlider_interest: function (e) {
    var _this = this;
    var position = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var boFangImage = albumInfo[index].boFangImage;
    var startDate = util.digitalFormatTime(position);
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
      _this.setData({
        ["albumInfo[" + index + "].currentTime"]: position,
        ["albumInfo[" + index + "].boFangImage"]: api.AudioNoBoFangImage_Name
      });
      _this.voiceBoFang_interest(e);
    } else {
      // 未播放状态
      _this.setData({
        ["albumInfo[" + index + "].currentTime"]: position,
        ["albumInfo[" + index + "].startDate"]: startDate
      });
    }
  },

  /**
   * 跳转到视频播放页面：圈子详情
   */
  navigateToVideoInterest: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var albumInfo = _this.data.albumInfo;
    var interestid = _this.data.ordInterest.id;
    var src = albumInfo[index].ip + albumInfo[index].videourl;
    wx.navigateTo({
      url: "../../../../../../pages/home/video/video?state=1&type=1&id=" + interestid + "&src=" + src
    })
  },

  /**
   * 关注或取消关注
   */
  interestinFocus: function (e) {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      var wechatopenid = _this.data.mainUser.openid;
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.wechatopenid = wechatopenid;
        data.openid = openid;
        data.access_token = res.access_token;
        util.post(api.Home_FocusOrCancelApiUrl, data).then(function (res) {
          if (res.code == 200) {
            _this.setData({
              thisUserFocusCount: res.result.count
            })
          }
        })
      })
    }
  },

  /**
   * 语音拒绝授权的提示弹窗关闭
   */
  audioOauhRefusedDialogClose: function () {
    var _this = this;
    _this.setData({
      audioOauhRefusedDialogShow: false
    })
  },

  /**
   * 语音拒绝授权的提示弹窗确认动作
   */
  audioOauhRefusedDialogSuccess: function () {
    var _this = this;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.record"] == true) {
          // 授权成功
          _this.audioOauhRefusedDialogClose();
        } else {
          // 授权失败
          _this.audioOauhRefusedDialogClose();
        }
      }
    })
  },

  /**
   * 进入个人简介设置
   */
  navigateToIntro: function(){
    wx.navigateTo({
      url: '../../../personinfo/homesetup/intro/intro'
    })
  },

  /**
   * 获取票种信息
   */
  getOrdAmounts: function(){
    var _this = this;
    var circleid = _this.data.circleid;
    var openid = app.globalData.logininfo.openid;
    var param = {};
    param.circleid = circleid;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        param.openid = openid;
        param.access_token = res.access_token;
        _this.getOrdAmountsQuery(api.Interest_getOrdAmountsApi, param);
      })
    }else{
      _this.getOrdAmountsQuery(api.Interest_getOrdAmounts, param);
    }
  },

  /**
   * 获取票种信息：请求
   */
  getOrdAmountsQuery: function(query, param){
    var _this = this;
    util.post(query, param).then(function (res) {
      if (res.code == 200) {
        var amount = res.result.obj;
        var amountDetails = res.result.list;
        _this.setData({
          amount: amount,
          amountDetails: amountDetails
        })
        var selectNumber = 0;
        if (amountDetails.length > 0) {
          var shareAmountDetailsId = _this.data.shareAmountDetailsId;
          if (shareAmountDetailsId > 0){
            // 有分享的
            var selectTicketIndex = null;
            for (var i = 0; i < amountDetails.length; i++) {
              if(amountDetails[i].id == shareAmountDetailsId){
                selectTicketIndex = i;
              }
            }
            if (selectTicketIndex != null){
              var buyNumber = amountDetails[selectTicketIndex].buyNumber;
              var amountDetailsId = amountDetails[selectTicketIndex].id;
              selectNumber = buyNumber > 0 ? 1 : 0;
              // 需要调用后台接口计算价格
              _this.calculationTicketPrice(selectNumber, amountDetailsId);
              _this.setData({
                ["ticket.selectTicketIndex"]: selectTicketIndex
              })
            }
          }else{
            var selectTicketIndex = _this.data.ticket.selectTicketIndex;
            var buyNumber = amountDetails[selectTicketIndex].buyNumber;
            var amountDetailsId = amountDetails[selectTicketIndex].id;
            selectNumber = buyNumber > 0 ? 1 : 0;
            // 需要调用后台接口计算价格
            _this.calculationTicketPrice(selectNumber, amountDetailsId);
          }
        }
      }
    })
  },

  /**
   * 数字减
   */
  buyNumberJian: function () {
    var _this = this;
    var selectTicketIndex = _this.data.ticket.selectTicketIndex;
    var amountDetailsId = _this.data.amountDetails[selectTicketIndex].id;
    var selectNumber = _this.data.ticket.selectNumber;
    if (selectNumber > 1) {
      selectNumber = selectNumber - 1;
      // 需要调用后台接口计算价格
      _this.calculationTicketPrice(selectNumber, amountDetailsId);
    }
  },

  /**
   * 数字加
   */
  buyNumberJia: function () {
    var _this = this;
    var amountDetails = _this.data.amountDetails;
    var selectTicketIndex = _this.data.ticket.selectTicketIndex;
    var buyNumber = amountDetails[selectTicketIndex].buyNumber;
    var amountDetailsId = amountDetails[selectTicketIndex].id;
    var selectNumber = _this.data.ticket.selectNumber;
    if (selectNumber < buyNumber){
      selectNumber = selectNumber + 1;
      // 需要调用后台接口计算价格
      _this.calculationTicketPrice(selectNumber, amountDetailsId);
    }
  },

  /**
   * 计算用户选的票种价格
   */
  calculationTicketPrice: function (selectNumber, amountDetailsId, isShowToast = false){
    wx.showLoading({
      title: '计算中',
    })
    var _this = this;
    var circleid = _this.data.circleid;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var param = {};
        param.openid = openid;
        param.circleid = circleid;
        param.access_token = res.access_token;
        param.amountDetailsId = amountDetailsId;
        param.buySize = selectNumber;
        util.post(api.Interest_CalculationTicketPrice, param).then(function (res) {
          wx.hideLoading();
          if (res.code == 200) {
            _this.setData({
              ["ticket.orangeShell"]: res.result.json.orangeShell,
              ["ticket.totalMoney"]: res.result.json.totalMoney,
              ["ticket.selectNumber"]: selectNumber
            })
            var itemTypeIdentification = _this.data.ordInterest.itemTypeIdentification;
            if (itemTypeIdentification == 1) {
              var userInfo = [];
              for (var i = 0; i < selectNumber; i++) {
                var data = {};
                data.realname = "";
                data.phonenumber = "";
                data.age = "";
                data.gender = 1;
                data.wechat = "";
                data.remark = "";
                data.isHidden = false;
                userInfo.push(data);
              }
              _this.setData({
                ["ticket.userInfo"]: userInfo
              })
            }
          } else {
            if (isShowToast) {
              util.showToast(res.message, "none")
            }
          }
        })
      })
    }
  },

  /**
   * 下一步
   */
  next1: function(){
    // 判断是否为线下项目
    var _this = this;
    var itemTypeIdentification = _this.data.ordInterest.itemTypeIdentification;
    var selectTicketIndex = _this.data.ticket.selectTicketIndex;
    var orangeShell = _this.data.ticket.orangeShell;
    var totalMoney = _this.data.ticket.totalMoney;
    var selectNumber = _this.data.ticket.selectNumber;
    var amountDetails = _this.data.amountDetails;
    if (selectNumber > 0){
      _this.setData({
        ["ticket.next1_submit"]: true
      })
      if (itemTypeIdentification == 1) {
        // 线下活动
        _this.selectTicketClose();
        _this.userInfoShow();
      } else {
        // 判断是否是橙贝票种
        if (amountDetails[selectTicketIndex].preferentialSettings == 2) {
          _this.selectTicketClose();
          _this.orangeShellPayShow();
        } else {
          // 进行生成订单
          _this.saveOrdInterestJoin_real();
        }
      }
    }
  },

  /**
   * 正在进行中的团购信息弹窗打开
   */
  groupbuyDialogShow: function () {
    var _this = this;
    _this.setData({
      ["ticket.groupbuyDialogShow"]: true
    })
  },

  /**
   * 正在进行中的团购信息弹窗关闭
   */
  groupbuyDialogClose: function () {
    var _this = this;
    _this.setData({
      ["ticket.groupbuyDialogShow"]: false
    })
  },

  /**
   * 线下活动，填写用户信息弹窗
   */
  userInfoShow: function () {
    var _this = this;
    _this.setData({
      ["ticket.userInfoShow"]: true
    })
  },

  /**
   * 线下活动，填写用户信息弹窗
   */
  userInfoClose: function () {
    var _this = this;
    _this.setData({
      ["ticket.userInfoShow"]: false
    })
  },


  /**
   * 橙贝兑换的支付弹窗开启
   */
  orangeShellPayShow: function () {
    var _this = this;
    _this.setData({
      ["ticket.orangeShellPayShow"]: true
    })
  },

  /**
   * 橙贝兑换的支付弹窗关闭
   */
  orangeShellPayClose: function () {
    var _this = this;
    _this.setData({
      ["ticket.orangeShellPayShow"]: false
    })
  },
  
  /**
   * 用户信息，返回上一页
   */
  userInfoReturn: function(){
    var _this = this;
    _this.userInfoClose();
    _this.selectTicketShow();
  },

  /**
   * 橙贝兑换的支付页面返回上一页
   */
  orangeShellPayReturn: function(){
    var _this = this;
    var orangeShellPayProgress = _this.data.ticket.orangeShellPayProgress;
    if (orangeShellPayProgress == 2){
      _this.setData({
        ["ticket.orangeShellPayProgress"]: 1
      })
    } else if (orangeShellPayProgress == 1) {
      _this.orangeShellPayClose();
      var itemTypeIdentification = _this.data.ordInterest.itemTypeIdentification;
      if (itemTypeIdentification == 1){
        // 线上活动
        _this.userInfoShow();
      } else {
        _this.selectTicketShow();
      }
    }
  },

  /**
   * 确认支付橙贝
   */
  orangeShellPay: function(){
    var _this = this;
    _this.setData({
      ["ticket.orangeShellPayProgress"]: 2
    })
  },

  /**
   * 团购弹窗打开
   */
  groupbuyShow: function (orderNum) {
    var _this = this;
    _this.setData({
      ["ticket.groupbuyShow"]: true
    })
  },

  /**
   * 团购弹窗关闭
   */
  groupbuyClose: function () {
    var _this = this;
    _this.setData({
      ["ticket.groupbuyShow"]: false
    })
  },

  /**
  * 获取用户资金信息
  */
  getUserCapital: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var param = {};
        param.access_token = res.access_token;
        param.openid = openid;
        util.post(api.My_GetUserCapitalApiUrl, param).then(function (res) {
          if (res.code == 200) {
            _this.setData({
              userCapital: res.result.entity
            })
          }
        })
      })
    }
  },

  /**
   * 获取正在进行中的团购信息
   */
  getOngoingAmountDetailsGroupbuy: function(){
    var _this = this;
    var circleid = _this.data.circleid;
    var param = {};
    param.circleid = circleid;
    util.post(api.Interest_GetOngoingAmountDetailsGroupbuy, param).then(function (res) {
      if (res.code == 200) {
        _this.setData({
          ongoingAmountDetailsGroupbuy: res.result.list
        })
      }
    })
  },

  /**
   * 成员信息：编辑切换
   */
  userInfoEditor: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var isHidden = _this.data.ticket.userInfo[index].isHidden;
    _this.setData({
      ["ticket.userInfo[" + index + "].isHidden"]: !isHidden
    })
  },

  /**
   * 成员信息：姓名输入事件
   */
  realnameInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.target.dataset.index;
    _this.setData({
      ["ticket.userInfo[" + index + "].realname"]: String(value).trim()
    })
  },

  /**
   * 成员信息：手机号输入事件
   */
  phoneInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.target.dataset.index;
    _this.setData({
      ["ticket.userInfo[" + index + "].phone"]: value
    })
  },

  /**
   * 成员信息：微信号输入事件
   */
  wechatInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.target.dataset.index;
    _this.setData({
      ["ticket.userInfo[" + index + "].wechat"]: value
    })
  },

  /**
   * 成员信息：年龄输入事件
   */
  ageInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.target.dataset.index;
    if (parseInt(value) <= 0){
      value = 1;
    }
    _this.setData({
      ["ticket.userInfo[" + index + "].age"]: value
    })
  },

  /**
   * 成员信息：备注输入事件
   */
  remarkInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.target.dataset.index;
    _this.setData({
      ["ticket.userInfo[" + index + "].remark"]: value
    })
  },

  /**
   * 成员信息：性别切换
   */
  genderTap: function (e) {
    var _this = this;
    var value = e.currentTarget.dataset.value;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      ["ticket.userInfo[" + index + "].gender"]: value
    })
  },

  /**
   * 成员信息：手机号的input的鼠标移出事件
   */
  phoneBlur: function (e) {
    var _this = this;
    var index = e.target.dataset.index;
    var value = e.detail.value;
    if (value != null && String(value).length > 0){
      _this.checkPhone(value);
    }
  },

  /**
   * 校验手机号
   */
  checkPhone: function (phone) {
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(phone)) {
      util.dialogAlert("请输入正确的手机号");
      return false;
    }
    return true;
  },

  /**
   * 成员信息：下一步
   */
  userInfoNext: function () {
    var _this = this;
    var userInfo = _this.data.ticket.userInfo;
    var flag = true;
    for (var i = 0; i < userInfo.length; i++) {
      var realname = userInfo[i].realname;
      var phone = userInfo[i].phone;
      if (realname == null || String(realname).trim().length <= 0){
        util.dialogAlert("请输入姓名");
        flag = false;
      }
      if (phone == null || String(phone).trim().length <= 0){
        util.dialogAlert("请输入手机号");
        flag = false;
      }
      if (!_this.checkPhone(phone)) {
        flag = false;
      }
    }
    // 提交
    if (flag) {
      var amountDetails = _this.data.amountDetails;
      var selectTicketIndex = _this.data.ticket.selectTicketIndex;
      if (amountDetails[selectTicketIndex].preferentialSettings == 2) {
        _this.userInfoClose();
        _this.orangeShellPayShow();
      } else {
        // 进行生成订单
        _this.saveOrdInterestJoin_real();
      }
    }
  },

  /**
   * 团购：加入别人的队伍
   */
  amountDetailsGroupbuySelect: function(e){
    var _this = this;
    var index = e.target.dataset.index;
    var amountDetailsGroupbuy = _this.data.ongoingAmountDetailsGroupbuy[index];
    var amountDetailsId = amountDetailsGroupbuy.amountDetailsId;
    var amountDetailsGroupbuyId = amountDetailsGroupbuy.id;
    _this.setData({
      ["ticket.amountDetailsGroupbuyId"]: amountDetailsGroupbuyId
    })
    _this.groupbuyDialogClose();
    var dataset = { "isexperience": 0 };
    var currentTarget = { "dataset": dataset };
    var e = { "currentTarget": currentTarget};
    _this.saveOrdInterestJoin2(e);
  },

  /**
   * 进入创建主题页面
   */
  navigateToCreateTheme: function () {
    var _this = this;
    var themeType = _this.data.ordInterest.themeType;
    if (themeType != null) {
      // 已经选择了类型
      wx.navigateTo({
        url: "../../../../../../interest/pages/interest/theme/makeTheme/makeTheme?o_type=create&type=" + themeType + "&circleid=" + _this.data.circleid
      })
    } else {
      wx.navigateTo({
        url: "../../../../../../interest/pages/interest/theme/themeIndex?circleid=" + _this.data.circleid
      })
    }
  },

  /**
   * 跳转到主题详情
   */
  themeDetail: function (e) {
    var _this = this;
    var themeid = e.currentTarget.dataset.themeid;
    var themeContentType = e.currentTarget.dataset.contenttype;
    if (themeContentType == 4 || themeContentType == 5) {
      // 宝贝
      wx.navigateTo({
        url: '../../../../../../interest/pages/interest/theme/goodsDetails/goodsDetails?themeid=' + themeid,
      })
    } else {
      wx.navigateTo({
        url: '../../../../../../interest/pages/interest/theme/themeDetails/themeDetails?themeid=' + themeid,
      })
    }
  },


  /**
   *  开通店铺弹窗
   */
  preferentialOpenStoreDialogShow: function () {
    var _this = this;
    _this.setData({
      preferentialOpenStoreDialogShow: true,
      openStoreDialogShow: false
    })
  },

  /**
   * 圈子分销
   */
  circleDistribution: function (e) {
    // 未开通店铺弹窗，进行弹窗
    var _this = this;
    var type = e.target.dataset.type;
    var circleid = _this.data.circleid;
    // 校验当前用户是否有开通店铺
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var param = {};
        param.access_token = res.access_token;
        param.openid = openid;
        param.circleid = circleid;
        util.post(api.My_checkUserOpenStoreApi, param).then(function (res2) {
          if (res2.code == 200) {
            var obj = res2.result.obj;
            if (!obj.isOpen) {
              // 未开通
              var openStorePrice = obj.openStorePrice;// 开通原价
              var storePreferentialPrice = obj.storePreferentialPrice;
              var preferentialPrice = storePreferentialPrice.preferentialPrice;// 开通优惠价格
              var openText = "";
              var openPrice = 0;
              var openType = 1;
              if (preferentialPrice > 0 && preferentialPrice < openStorePrice) {
                openText = "优惠";
                openType = 1;
                openPrice = openStorePrice - preferentialPrice;
              } else if (preferentialPrice > 0 && preferentialPrice == openStorePrice) {
                openText = "免费";
                openType = 2;
                openPrice = 0;
              } else {
                openText = "";
                openPrice = openStorePrice;
                openType = 3;
              }
              obj.openText = openText;
              obj.openPrice = openPrice;
              obj.openType = openType;
              _this.setData({
                openStoreInfo: obj
              })
              _this.openStoreDialogShow();
            } else {
              if (type == 1) {
                // 进入店铺
                wx.navigateTo({
                  url: '../../../../../../grade/pages/grade/myStore/myStore?openid=' + _this.data.mainUser.openid,
                })
              } else {
                var distributionCount = obj.distributionCount;
                if (distributionCount <= 0) {
                  // 未加入分销
                  _this.joinCommissionShow();
                } else {
                  var distributionDetails = obj.distributionDetails;
                  var shareImage = distributionDetails.shareImageIp + distributionDetails.shareImageUrl;
                  _this.setData({
                    ["shareInfo.circleid"]: circleid,
                    ["shareInfo.shareImage"]: shareImage,
                    ["shareInfo.shareImageDialogShow"]: true
                  })
                }
              }
            }
          }
        })
      });
    }
  },

  /**
   * 加入店铺弹窗
   */
  joinCommissionShow: function () {
    var _this = this;
    _this.setData({
      joinCommissionShow: true
    })
  },

  /**
   *  未开通店铺弹窗
   */
  openStoreDialogShow: function () {
    var _this = this;
    _this.setData({
      openStoreDialogShow: true
    })
  },

  /**
   *  开通店铺弹窗关闭
   */
  preferentialOpenStoreDialogClose: function () {
    var _this = this;
    _this.setData({
      preferentialOpenStoreDialogShow: false,
      storeDialogShowIndex: "",
      openStoreInfo: {}
    })
  },

  /**
   * 开通店铺
   */
  preferentialOpenStoreDialogSuccess: function () {
    var _this = this;
    var openStoreInfo = _this.data.openStoreInfo;
    var openStorePrice = openStoreInfo.openStorePrice;// 开通原价
    var preferentialPrice = openStoreInfo.storePreferentialPrice.preferentialPrice;// 开通优惠价格
    var payStorePrice = openStorePrice - preferentialPrice;// 需要支付的金额
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      wx.showLoading({
        title: '开通店铺中',
      })
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var param = {};
        param.access_token = res.access_token;
        param.payStorePrice = payStorePrice;// 用于校验页面展示金额是否和实际支付金额一致
        param.openid = openid;
        util.post(api.My_openStoreApi, param).then(function (res2) {
          if (res2.code == 200) {
            var buyJoinState = res2.result.buyJoinState;
            var json = res2.result.obj;
            var orderNum = json.orderNum;
            var totalMoney = json.totalMoney;
            if (buyJoinState == 1) {
              // 不需要支付
              util.showToast("开通店铺成功~", "success");
              _this.preferentialOpenStoreDialogClose();
            } else {
              // 需要调用微信支付
              _this.wechatCallbackBusiness(orderNum, totalMoney);
            }
          } else {
            util.showToast(res2.message, "none");
          }
          wx.hideLoading();
        })
      });
    }
  },

  /**
   * 微信支付回调：这个应该是支付后自动触发，但是开发阶段，就代码触发
   */
  wechatCallbackBusiness: function (orderNum, totalMoney) {
    var _this = this;
    var param = {};
    param.orderNum = orderNum;
    param.actualPrice = totalMoney;
    param.outTradeNo = new Date().getTime();
    util.post(api.Interest_WechatCallback, param, "application/x-www-form-urlencoded;charset=UTF-8").then(function (res) {
      wx.showLoading({
        title: '支付中',
      })
      getOrderByOrderNumInterval = setInterval(function () {
        _this.getOrderByOrderNum(orderNum);
      }, 1000);
    })
  },

  /**
   * 加入店铺弹窗关闭
   */
  joinCommissionClose: function () {
    var _this = this;
    _this.setData({
      joinCommissionShow: false
    })
  },

  /**
   * 确定分销
   */
  joinCommissionSuccess: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      wx.showLoading({
        title: '提交中',
      })
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var param = {};
        param.openid = openid;
        param.circleid = circleid;
        param.access_token = res.access_token;
        param.commissionJoinType = 1;
        util.post(api.Interest_joinCommissionInterest, param).then(function (res2) {
          wx.hideLoading();
          if (res2.code == 200) {
            var obj = res2.result.obj;
            _this.setData({
              ["shareInfo.circleid"]: circleid,
              ["shareInfo.shareImage"]: obj,
              ["shareInfo.shareImageDialogShow"]: true
            })
            _this.joinCommissionClose();
          } else {
            util.showToast(res2.message, "none");
          }
        })
      });
    }
  },

  /**
   * 关闭分销的分享图片
   */
  shareImageDialogClose: function () {
    var _this = this;
    util.showToast("此分销项目已入驻你的店铺，请及时推广分享", "none");
    _this.setData({
      shareInfo: { "shareImageDialogShow": false, "shareImage": "", "circleid": "" }
    })
  },

  /**
   * 保存图片到相册
   */
  onSavePicClick: function (e) {
    var _this = this;
    var downloadUrl = e.target.dataset.path;
    // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.writePhotosAlbum" 这个 scope  
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.writePhotosAlbum'] == false) {
          // 没有授权《保存图片》权限
          _this.setData({
            photoDialogShow: true
          })
        } else {
          //已经授权《保存图片》权限
          util.downloadImage(downloadUrl);
        }
      },
      fail(res) {
      }
    })
  },

  /**
   * 关闭没有授权《保存图片》弹窗
   */
  photoDialogClose: function () {
    var _this = this;
    _this.setData({
      photoDialogShow: false
    })
  },

  /**
   * 《保存图片》未授权的弹窗确认动作
   */
  photoDialogSuccess: function (e) {
    var _this = this;
    var downloadUrl = e.target.dataset.path;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.writePhotosAlbum"] == true) {
          // 授权成功
          _this.photoDialogClose();
          util.downloadImage(downloadUrl)
        } else {
          // 授权失败
          _this.photoDialogClose();
        }
      }
    })
  },
  selectMenu: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    if (index != null) {
      var toView = "theme" + index;
      _this.setData({
        toView: toView
      })
    }
  },

  right: function(e){
    
  }
})